Skip to content

Commit

Permalink
Merge pull request #12 from opensatelliteproject/NewRadios
Browse files Browse the repository at this point in the history
New radios
  • Loading branch information
racerxdl authored Mar 25, 2017
2 parents c1dfa0b + 4ceece3 commit 4ebaf35
Show file tree
Hide file tree
Showing 13 changed files with 1,066 additions and 188 deletions.
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ before_install:
- sudo add-apt-repository ppa:myriadrf/drivers -y
- sudo add-apt-repository ppa:myriadrf/gnuradio -y
- sudo apt-get -qq update
- sudo apt-get install -y libairspy-dev libusb-1.0-0-dev
- sudo apt-get install -y libairspy-dev libusb-1.0-0-dev libhackrf-dev libhackrf0
env:
- CTEST_OUTPUT_ON_FAILURE=1 CMAKE_INSTALL_PREFIX=/usr

script:
- make libcorrect && sudo make libcorrect-install && make libSatHelper && sudo make libSatHelper-install && make && make test
- make libcorrect && sudo make libcorrect-install && make libSatHelper && sudo make libSatHelper-install && make librtlsdr && sudo make librtlsdr-install && make && make test
21 changes: 21 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,17 @@ libSatHelper: FORCE
@echo -e '\033[0;32mFinished building target: $@\033[0m'
@echo ' '

librtlsdr: FORCE
@echo -e '\033[0;32mBuilding target: $@\033[0m'
@echo -e '\033[0;34m'
@git clone https://github.com/librtlsdr/librtlsdr
@mkdir librtlsdr/build -p
@cd librtlsdr/build && cmake ..
$(MAKE) -C librtlsdr/build
@echo -e '\033[0m'
@echo -e '\033[0;32mFinished building target: $@\033[0m'
@echo ' '

libSatHelper-install: FORCE
@echo -e '\033[0;32mInstalling target: $@\033[0m'
@echo -e '\033[0;34m'
Expand All @@ -67,6 +78,16 @@ libSatHelper-install: FORCE
@echo -e '\033[0;32mFinished installing target: $@\033[0m'
@echo ' '

librtlsdr-install: FORCE
@echo -e '\033[0;32mInstalling target: $@\033[0m'
@echo -e '\033[0;34m'
$(MAKE) -C librtlsdr/build install
@echo -e 'Running ldconfig'
@ldconfig
@echo -e '\033[0m'
@echo -e '\033[0;32mFinished installing target: $@\033[0m'
@echo ' '

test:
@echo -e '\033[0;32mNothing to test\033[0m'

Expand Down
4 changes: 3 additions & 1 deletion demodulator/.cproject
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,9 @@
</option>
<option id="gnu.cpp.compiler.option.other.other.1348803267" name="Other flags" superClass="gnu.cpp.compiler.option.other.other" value="-c -fmessage-length=0" valueType="string"/>
<option id="gnu.cpp.compiler.option.warnings.pedantic.2025753002" name="Pedantic (-pedantic)" superClass="gnu.cpp.compiler.option.warnings.pedantic" value="false" valueType="boolean"/>
<option id="gnu.cpp.compiler.option.preprocessor.def.1368866537" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def"/>
<option id="gnu.cpp.compiler.option.preprocessor.def.1368866537" name="Defined symbols (-D)" superClass="gnu.cpp.compiler.option.preprocessor.def" valueType="definedSymbols">
<listOptionValue builtIn="false" value="NON_FREE"/>
</option>
<inputType id="cdt.managedbuild.tool.gnu.cpp.compiler.input.639949404" superClass="cdt.managedbuild.tool.gnu.cpp.compiler.input"/>
</tool>
<tool id="cdt.managedbuild.tool.gnu.c.compiler.exe.debug.1361537906" name="GCC C Compiler" superClass="cdt.managedbuild.tool.gnu.c.compiler.exe.debug">
Expand Down
17 changes: 17 additions & 0 deletions demodulator/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,11 @@ add_definitions(-DGIT_SHA1=${GIT_SHA1})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -O3")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -Wall -O3")

if (DEBUG)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g")
endif()

# Source Code
file(GLOB SOURCES src/*.cpp)

Expand All @@ -46,12 +51,24 @@ if(WIN32)
target_link_libraries (${PROJECT_NAME} airspy.a)
target_link_libraries (${PROJECT_NAME} usb-1.0.a)
target_link_libraries (${PROJECT_NAME} pthread.a)
target_link_libraries (${PROJECT_NAME} rtlsdr.a)
target_link_libraries (${PROJECT_NAME} hackrf.a)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -static-libgcc -static-libstdc++")
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -static-libgcc -static-libstdc++")
if(NON_FREE)
message(ERROR "Please compile using Visual Studio. NON FREE not supported by Mingw")
endif()
else()
target_link_libraries (${PROJECT_NAME} airspy)
target_link_libraries (${PROJECT_NAME} usb-1.0)
target_link_libraries (${PROJECT_NAME} pthread)
target_link_libraries (${PROJECT_NAME} rtlsdr)
target_link_libraries (${PROJECT_NAME} hackrf)
if(NON_FREE)
message(STATUS "Enabling NON-FREE mode")
add_definitions(-DNON_FREE)
target_link_libraries (${PROJECT_NAME} mirsdrapi-rsp)
endif()
endif()


Expand Down
224 changes: 224 additions & 0 deletions demodulator/src/HackRFFrontend.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
/*
* HackRFFrontend.cpp
*
* Created on: 26/02/2017
* Author: Lucas Teske
*/

#include "HackRFFrontend.h"
#include <SatHelper/exceptions.h>
#include <iostream>
#include <cmath>


const std::string HackRFFrontend::FrontendName = "HackRF OSP Plugin";
const std::vector<uint32_t> HackRFFrontend::supportedSampleRates = {
8000000, 10000000, 12500000, 16000000, 20000000
};

void HackRFFrontend::Initialize() {
int err = hackrf_init();
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error initializing HackRF: " << msg << std::endl;
}
}

void HackRFFrontend::DeInitialize() {

}


int HackRFFrontend::callback(hackrf_transfer* transfer) {
HackRFFrontend *ctx = (HackRFFrontend *)transfer->rx_ctx;
if (transfer->valid_length > ctx->bufferLength) {
if (ctx->buffer != NULL) {
delete[] ctx->buffer;
}

ctx->buffer = new float[transfer->valid_length];
ctx->bufferLength = transfer->valid_length;
}

for (int i=0; i<transfer->valid_length; i++) {
ctx->buffer[i] = ctx->lut[transfer->buffer[i]];
if (i%1) {
ctx->qavg += ctx->alpha * (ctx->buffer[i] - ctx->qavg);
ctx->buffer[i] -= ctx->qavg;
} else {
ctx->iavg += ctx->alpha * (ctx->buffer[i] - ctx->iavg);
ctx->buffer[i] -= ctx->iavg;
}
}

ctx->cb(ctx->buffer, transfer->valid_length / 2, FRONTEND_SAMPLETYPE_FLOATIQ);

return 0;
}


HackRFFrontend::HackRFFrontend(int deviceNumber) {
hackrf_device_list_t *devices = hackrf_device_list();
if (deviceNumber >= devices->devicecount) {
std::cerr << "There is no such device as id " << deviceNumber << std::endl;
throw SatHelperException("No such device");
}
this->deviceNumber = deviceNumber;
device = NULL;
hackrf_device_list_free(devices);
lnaGain = 0;
vgaGain = 0;
mixerGain = 0;
centerFrequency = 106300000;
sampleRate = 8000000;
buffer = NULL;
bufferLength = 0;
alpha = 1.f - exp(-1.0 / (sampleRate * 0.05f));
iavg = 0;
qavg = 0;
for (int i = 0; i < 256; i++) {
lut[i] = (i - 128) * (1.f / 127.f);
}
}

HackRFFrontend::~HackRFFrontend() {
if (buffer != NULL) {
delete[] buffer;
}
}

uint32_t HackRFFrontend::SetSampleRate(uint32_t sampleRate) {
if (device != NULL) {
double sr = sampleRate / 1e6;
int err = hackrf_set_sample_rate(device, sr);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error setting sample rate HackRF: " << msg << std::endl;
}
}

this->sampleRate = sampleRate;;
return sampleRate;
}

uint32_t HackRFFrontend::SetCenterFrequency(uint32_t centerFrequency) {
if (device != NULL) {
int err = hackrf_set_freq(device, centerFrequency);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error setting center frequency HackRF: " << msg << std::endl;
}
}

this->centerFrequency = centerFrequency;
return centerFrequency;
}

const std::vector<uint32_t>& HackRFFrontend::GetAvailableSampleRates() {
return supportedSampleRates;
}

void HackRFFrontend::Start() {
alpha = 1.f - exp(-1.0 / (sampleRate * 0.05f));
iavg = 0;
qavg = 0;
hackrf_device_list_t *devices = hackrf_device_list();

std::cout << "Getting HackRF Devices" << std::endl;
int err = hackrf_device_list_open(devices, deviceNumber, &device);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error listing devices: " << msg << std::endl;
}

std::cout << "Disabling Input LNA for safety." << std::endl;

err = hackrf_set_amp_enable(device, 0);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error disabling input LNA: " << msg << std::endl;
}

std::cout << "Setting LNA Gain to " << (int)lnaGain << std::endl;
SetLNAGain(lnaGain);
std::cout << "Setting VGA Gain to " << (int)vgaGain << std::endl;
SetVGAGain(vgaGain);
std::cout << "Setting Sample Rate to " << sampleRate << std::endl;
SetSampleRate(sampleRate);

uint32_t bwfilter = hackrf_compute_baseband_filter_bw(4000000);
std::cout << "Computed Bandwidth Filter: " << bwfilter << std::endl;

err = hackrf_set_baseband_filter_bandwidth(device, bwfilter);

if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error setting input bandwidth: " << msg << std::endl;
}

err = hackrf_start_rx(device, HackRFFrontend::callback, this);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error initializing HackRF: " << msg << std::endl;
}

std::cout << "Setting Center Frequency to " << centerFrequency << std::endl;
SetCenterFrequency(centerFrequency);

hackrf_device_list_free(devices);
}

void HackRFFrontend::Stop() {
if (device != NULL) {
hackrf_close((hackrf_device *)device);
}
}

void HackRFFrontend::SetAGC(bool agc) {
if (agc == true) {
std::cout << "AGC not implemented for HackRF. Please set the gains manually." << std::endl;
throw SatHelperException("No hardware AGC available");
}
}

void HackRFFrontend::SetLNAGain(uint8_t value) {
if (device != NULL) {
int err = hackrf_set_lna_gain(device, value);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error setting LNA Gain for HackRF: " << msg << std::endl;
}
}
lnaGain = value;
}

void HackRFFrontend::SetVGAGain(uint8_t value) {
if (device != NULL) {
int err = hackrf_set_vga_gain(device, value);
if (err != HACKRF_SUCCESS) {
const char *msg = hackrf_error_name((hackrf_error)err);
std::cerr << "Error setting VGA Gain for HackRF: " << msg << std::endl;
}
}
vgaGain = value;
}

void HackRFFrontend::SetMixerGain(uint8_t value) {
std::cerr << "HackRF does not have mixer gain." << std::endl;
}

uint32_t HackRFFrontend::GetCenterFrequency() {
return centerFrequency;
}

const std::string &HackRFFrontend::GetName() {
return FrontendName;
}

uint32_t HackRFFrontend::GetSampleRate() {
return sampleRate;
}

void HackRFFrontend::SetSamplesAvailableCallback(std::function<void(void*data, int length, int type)> cb) {
this->cb = cb;
}
63 changes: 63 additions & 0 deletions demodulator/src/HackRFFrontend.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* HackRFFrontend.h
*
* Created on: 26/02/2017
* Author: Lucas Teske
*/

#ifndef SRC_HACKRFFRONTEND_H_
#define SRC_HACKRFFRONTEND_H_

#include "FrontendDevice.h"
#include <libhackrf/hackrf.h>

class HackRFFrontend: public FrontendDevice {
private:
std::function<void(void*data, int length, int type)> cb;
hackrf_device *device;
int deviceNumber;
static const std::string FrontendName;
static const std::vector<uint32_t> supportedSampleRates;

static int callback(hackrf_transfer* transfer);

uint8_t lnaGain;
uint8_t vgaGain;
uint8_t mixerGain;

uint32_t centerFrequency;
uint32_t sampleRate;
float *buffer;
float lut[256];
int bufferLength;
float alpha;
float iavg;
float qavg;
public:
static void Initialize();
static void DeInitialize();

HackRFFrontend(int deviceNum);
virtual ~HackRFFrontend();

uint32_t SetSampleRate(uint32_t sampleRate) override;
uint32_t SetCenterFrequency(uint32_t centerFrequency) override;
const std::vector<uint32_t>& GetAvailableSampleRates() override;
void Start() override;
void Stop() override;
void SetAGC(bool agc) override;

void SetLNAGain(uint8_t value) override;
void SetVGAGain(uint8_t value) override;
void SetMixerGain(uint8_t value) override;

uint32_t GetCenterFrequency() override;

const std::string &GetName() override;

uint32_t GetSampleRate() override;

void SetSamplesAvailableCallback(std::function<void(void*data, int length, int type)> cb) override;
};

#endif /* SRC_HACKRFFRONTEND_H_ */
2 changes: 2 additions & 0 deletions demodulator/src/Parameters.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
#define AIRSPY_R2_DEFAULT_SAMPLERATE 2500000
#define DEFAULT_SAMPLE_RATE AIRSPY_MINI_DEFAULT_SAMPLERATE
#define DEFAULT_DECIMATION 1
#define DEFAULT_DEVICE_NUMBER 0

#define DEFAULT_DECODER_ADDRESS "127.0.0.1"
#define DEFAULT_DECODER_PORT 5000
Expand Down Expand Up @@ -70,6 +71,7 @@
#define CFG_PLL_ALPHA "pllAlpha"
#define CFG_DECODER_ADDRESS "decoderAddress"
#define CFG_DECODER_PORT "decoderPort"
#define CFG_DEVICE_NUM "deviceNumber"

// Compilation parameters

Expand Down
Loading

0 comments on commit 4ebaf35

Please sign in to comment.