2013-04-10 18:42:43 +00:00
|
|
|
/* -*- c++ -*- */
|
|
|
|
/*
|
|
|
|
* Copyright 2013 Dimitri Stolnikov <horiz0n@gmx.net>
|
2014-10-21 20:14:52 +00:00
|
|
|
* Copyright 2014 Hoernchen <la@tfc-server.de>
|
2020-01-26 23:48:59 +00:00
|
|
|
* Copyright 2020 Clayton Smith <argilo@gmail.com>
|
2013-04-10 18:42:43 +00:00
|
|
|
*
|
2020-01-26 23:48:59 +00:00
|
|
|
* gr-osmosdr is free software; you can redistribute it and/or modify
|
2013-04-10 18:42:43 +00:00
|
|
|
* 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.
|
|
|
|
*
|
2020-01-26 23:48:59 +00:00
|
|
|
* gr-osmosdr is distributed in the hope that it will be useful,
|
2013-04-10 18:42:43 +00:00
|
|
|
* 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
|
2020-01-26 23:48:59 +00:00
|
|
|
* along with gr-osmosdr; see the file COPYING. If not, write to
|
2013-04-10 18:42:43 +00:00
|
|
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
|
|
|
* Boston, MA 02110-1301, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* config.h is generated by configure. It contains the results
|
|
|
|
* of probing for features, options etc. It should be the first
|
|
|
|
* file included in your .cc file.
|
|
|
|
*/
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2013-04-28 10:36:03 +00:00
|
|
|
#include <stdexcept>
|
|
|
|
#include <iostream>
|
2013-05-06 19:52:19 +00:00
|
|
|
#include <algorithm>
|
|
|
|
#ifdef USE_AVX
|
|
|
|
#include <immintrin.h>
|
|
|
|
#elif USE_SSE2
|
|
|
|
#include <emmintrin.h>
|
|
|
|
#endif
|
2013-04-28 10:36:03 +00:00
|
|
|
|
2013-05-29 20:34:40 +00:00
|
|
|
#include <gnuradio/io_signature.h>
|
2013-04-10 18:42:43 +00:00
|
|
|
|
2013-04-28 10:36:03 +00:00
|
|
|
#include "hackrf_sink_c.h"
|
|
|
|
|
2013-05-30 14:14:22 +00:00
|
|
|
#include "arg_helpers.h"
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
static inline bool cb_init(circular_buffer_t *cb, size_t capacity, size_t sz)
|
|
|
|
{
|
|
|
|
cb->buffer = malloc(capacity * sz);
|
|
|
|
if(cb->buffer == NULL)
|
|
|
|
return false; // handle error
|
2015-12-07 19:37:32 +00:00
|
|
|
cb->buffer_end = (int8_t *)cb->buffer + capacity * sz;
|
2013-04-28 10:36:03 +00:00
|
|
|
cb->capacity = capacity;
|
|
|
|
cb->count = 0;
|
|
|
|
cb->sz = sz;
|
|
|
|
cb->head = cb->buffer;
|
|
|
|
cb->tail = cb->buffer;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline void cb_free(circular_buffer_t *cb)
|
|
|
|
{
|
2015-10-04 12:11:29 +00:00
|
|
|
free(cb->buffer);
|
|
|
|
cb->buffer = NULL;
|
2013-04-28 10:36:03 +00:00
|
|
|
// clear out other fields too, just to be safe
|
|
|
|
cb->buffer_end = 0;
|
|
|
|
cb->capacity = 0;
|
|
|
|
cb->count = 0;
|
|
|
|
cb->sz = 0;
|
|
|
|
cb->head = 0;
|
|
|
|
cb->tail = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cb_has_room(circular_buffer_t *cb)
|
|
|
|
{
|
|
|
|
if(cb->count == cb->capacity)
|
|
|
|
return false;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2020-01-26 23:48:59 +00:00
|
|
|
static inline bool cb_is_empty(circular_buffer_t *cb)
|
|
|
|
{
|
|
|
|
return cb->count == 0;
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:36:03 +00:00
|
|
|
static inline bool cb_push_back(circular_buffer_t *cb, const void *item)
|
|
|
|
{
|
|
|
|
if(cb->count == cb->capacity)
|
|
|
|
return false; // handle error
|
|
|
|
memcpy(cb->head, item, cb->sz);
|
2015-12-07 19:37:32 +00:00
|
|
|
cb->head = (int8_t *)cb->head + cb->sz;
|
2013-04-28 10:36:03 +00:00
|
|
|
if(cb->head == cb->buffer_end)
|
|
|
|
cb->head = cb->buffer;
|
|
|
|
cb->count++;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline bool cb_pop_front(circular_buffer_t *cb, void *item)
|
|
|
|
{
|
|
|
|
if(cb->count == 0)
|
|
|
|
return false; // handle error
|
|
|
|
memcpy(item, cb->tail, cb->sz);
|
2015-12-07 19:37:32 +00:00
|
|
|
cb->tail = (int8_t *)cb->tail + cb->sz;
|
2013-04-28 10:36:03 +00:00
|
|
|
if(cb->tail == cb->buffer_end)
|
|
|
|
cb->tail = cb->buffer;
|
|
|
|
cb->count--;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
hackrf_sink_c_sptr make_hackrf_sink_c (const std::string & args)
|
2013-04-10 18:42:43 +00:00
|
|
|
{
|
|
|
|
return gnuradio::get_initial_sptr(new hackrf_sink_c (args));
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Specify constraints on number of input and output streams.
|
|
|
|
* This info is used to construct the input and output signatures
|
2013-05-29 20:34:40 +00:00
|
|
|
* (2nd & 3rd args to gr::block's constructor). The input and
|
2013-04-10 18:42:43 +00:00
|
|
|
* output signatures are used by the runtime system to
|
|
|
|
* check that a valid number and type of inputs and outputs
|
|
|
|
* are connected to this block. In this case, we accept
|
2013-04-28 10:36:03 +00:00
|
|
|
* only 0 input and 1 output.
|
2013-04-10 18:42:43 +00:00
|
|
|
*/
|
2013-05-06 19:52:19 +00:00
|
|
|
static const int MIN_IN = 1; // mininum number of input streams
|
|
|
|
static const int MAX_IN = 1; // maximum number of input streams
|
|
|
|
static const int MIN_OUT = 0; // minimum number of output streams
|
|
|
|
static const int MAX_OUT = 0; // maximum number of output streams
|
2013-04-10 18:42:43 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
* The private constructor
|
|
|
|
*/
|
|
|
|
hackrf_sink_c::hackrf_sink_c (const std::string &args)
|
2013-05-29 20:34:40 +00:00
|
|
|
: gr::sync_block ("hackrf_sink_c",
|
|
|
|
gr::io_signature::make(MIN_IN, MAX_IN, sizeof (gr_complex)),
|
|
|
|
gr::io_signature::make(MIN_OUT, MAX_OUT, sizeof (gr_complex))),
|
2020-01-26 23:48:59 +00:00
|
|
|
hackrf_common::hackrf_common(args),
|
2013-04-28 10:36:03 +00:00
|
|
|
_buf(NULL),
|
2020-01-26 23:48:59 +00:00
|
|
|
_vga_gain(0)
|
2013-04-10 18:42:43 +00:00
|
|
|
{
|
2013-04-28 10:36:03 +00:00
|
|
|
dict_t dict = params_to_dict(args);
|
|
|
|
|
|
|
|
_buf_num = 0;
|
2013-04-10 18:42:43 +00:00
|
|
|
|
2013-04-28 10:36:03 +00:00
|
|
|
if (dict.count("buffers"))
|
2020-01-26 23:48:59 +00:00
|
|
|
_buf_num = std::stoi(dict["buffers"]);
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
if (0 == _buf_num)
|
|
|
|
_buf_num = BUF_NUM;
|
|
|
|
|
2020-01-26 23:48:59 +00:00
|
|
|
_stopping = false;
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
if ( BUF_NUM != _buf_num ) {
|
|
|
|
std::cerr << "Using " << _buf_num << " buffers of size " << BUF_LEN << "."
|
|
|
|
<< std::endl;
|
|
|
|
}
|
|
|
|
|
2013-10-25 21:36:32 +00:00
|
|
|
set_center_freq( (get_freq_range().start() + get_freq_range().stop()) / 2.0 );
|
2013-09-28 11:27:58 +00:00
|
|
|
set_sample_rate( get_sample_rates().start() );
|
|
|
|
set_bandwidth( 0 );
|
2013-04-28 10:36:03 +00:00
|
|
|
|
2014-10-21 20:10:40 +00:00
|
|
|
set_gain( 0 ); /* disable AMP gain stage by default to protect full sprectrum pre-amp from physical damage */
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
set_if_gain( 16 ); /* preset to a reasonable default (non-GRC use case) */
|
|
|
|
|
2015-05-27 21:55:00 +00:00
|
|
|
// Check device args to find out if bias/phantom power is desired.
|
|
|
|
if ( dict.count("bias_tx") ) {
|
2020-01-26 23:48:59 +00:00
|
|
|
hackrf_common::set_bias(dict["bias_tx"] == "1");
|
2015-05-27 21:55:00 +00:00
|
|
|
}
|
|
|
|
|
2015-12-07 19:37:32 +00:00
|
|
|
_buf = (int8_t *) malloc( BUF_LEN );
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
cb_init( &_cbuf, _buf_num, BUF_LEN );
|
2013-04-10 18:42:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Our virtual destructor.
|
|
|
|
*/
|
|
|
|
hackrf_sink_c::~hackrf_sink_c ()
|
|
|
|
{
|
2015-10-04 12:11:29 +00:00
|
|
|
free(_buf);
|
|
|
|
_buf = NULL;
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
cb_free( &_cbuf );
|
|
|
|
}
|
|
|
|
|
|
|
|
int hackrf_sink_c::_hackrf_tx_callback(hackrf_transfer *transfer)
|
|
|
|
{
|
|
|
|
hackrf_sink_c *obj = (hackrf_sink_c *)transfer->tx_ctx;
|
|
|
|
return obj->hackrf_tx_callback(transfer->buffer, transfer->valid_length);
|
|
|
|
}
|
|
|
|
|
|
|
|
int hackrf_sink_c::hackrf_tx_callback(unsigned char *buffer, uint32_t length)
|
|
|
|
{
|
|
|
|
#if 0
|
|
|
|
for (unsigned int i = 0; i < length; ++i) /* simulate noise */
|
|
|
|
*buffer++ = rand() % 255;
|
|
|
|
#else
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
std::unique_lock<std::mutex> lock(_buf_mutex);
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
if ( ! cb_pop_front( &_cbuf, buffer ) ) {
|
|
|
|
memset(buffer, 0, length);
|
2020-01-26 23:48:59 +00:00
|
|
|
if (_stopping) {
|
|
|
|
_buf_cond.notify_one();
|
|
|
|
return -1;
|
|
|
|
} else {
|
|
|
|
std::cerr << "U" << std::flush;
|
|
|
|
}
|
2013-04-28 10:36:03 +00:00
|
|
|
} else {
|
2013-05-08 19:37:30 +00:00
|
|
|
// std::cerr << "-" << std::flush;
|
2013-04-28 10:36:03 +00:00
|
|
|
_buf_cond.notify_one();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
return 0; // TODO: return -1 on error/stop
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hackrf_sink_c::start()
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
if ( ! _dev.get() )
|
2013-04-28 10:36:03 +00:00
|
|
|
return false;
|
|
|
|
|
2020-01-26 23:48:59 +00:00
|
|
|
_stopping = false;
|
2013-04-28 10:36:03 +00:00
|
|
|
_buf_used = 0;
|
2020-01-26 23:48:59 +00:00
|
|
|
hackrf_common::start();
|
|
|
|
int ret = hackrf_start_tx( _dev.get(), _hackrf_tx_callback, (void *)this );
|
2013-06-07 19:43:52 +00:00
|
|
|
if ( ret != HACKRF_SUCCESS ) {
|
2013-04-28 10:36:03 +00:00
|
|
|
std::cerr << "Failed to start TX streaming (" << ret << ")" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-08 19:37:30 +00:00
|
|
|
return true;
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hackrf_sink_c::stop()
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
int i;
|
|
|
|
|
|
|
|
if ( ! _dev.get() )
|
2013-04-28 10:36:03 +00:00
|
|
|
return false;
|
2020-01-26 23:48:59 +00:00
|
|
|
|
|
|
|
{
|
|
|
|
std::unique_lock<std::mutex> lock(_buf_mutex);
|
|
|
|
|
|
|
|
while ( ! cb_has_room(&_cbuf) )
|
|
|
|
_buf_cond.wait( lock );
|
|
|
|
|
|
|
|
// Fill the rest of the current buffer with silence.
|
|
|
|
memset(_buf + _buf_used, 0, BUF_LEN - _buf_used);
|
|
|
|
cb_push_back( &_cbuf, _buf );
|
|
|
|
_buf_used = 0;
|
|
|
|
|
|
|
|
// Add some more silence so the end doesn't get cut off.
|
|
|
|
memset(_buf, 0, BUF_LEN);
|
|
|
|
for (i = 0; i < 5; i++) {
|
|
|
|
while ( ! cb_has_room(&_cbuf) )
|
|
|
|
_buf_cond.wait( lock );
|
|
|
|
|
|
|
|
cb_push_back( &_cbuf, _buf );
|
|
|
|
}
|
|
|
|
|
|
|
|
_stopping = true;
|
|
|
|
|
|
|
|
while (hackrf_is_streaming(_dev.get()) == HACKRF_TRUE)
|
|
|
|
_buf_cond.wait( lock );
|
|
|
|
}
|
|
|
|
|
|
|
|
hackrf_common::stop();
|
|
|
|
int ret = hackrf_stop_tx( _dev.get() );
|
2013-06-07 19:43:52 +00:00
|
|
|
if ( ret != HACKRF_SUCCESS ) {
|
2013-04-28 10:36:03 +00:00
|
|
|
std::cerr << "Failed to stop TX streaming (" << ret << ")" << std::endl;
|
|
|
|
return false;
|
|
|
|
}
|
2013-05-08 19:37:30 +00:00
|
|
|
return true;
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-05-06 19:52:19 +00:00
|
|
|
#ifdef USE_AVX
|
2015-12-07 19:37:32 +00:00
|
|
|
void convert_avx(const float* inbuf, int8_t* outbuf,const unsigned int count)
|
2013-05-06 19:52:19 +00:00
|
|
|
{
|
|
|
|
__m256 mulme = _mm256_set_ps(127.0f, 127.0f, 127.0f, 127.0f, 127.0f, 127.0f, 127.0f, 127.0f);
|
|
|
|
for(unsigned int i=0; i<count;i++){
|
|
|
|
|
|
|
|
__m256i itmp3 = _mm256_cvtps_epi32(_mm256_mul_ps(_mm256_loadu_ps(&inbuf[i*16+0]), mulme));
|
|
|
|
__m256i itmp4 = _mm256_cvtps_epi32(_mm256_mul_ps(_mm256_loadu_ps(&inbuf[i*16+8]), mulme));
|
|
|
|
|
|
|
|
__m128i a1 = _mm256_extractf128_si256(itmp3, 1);
|
|
|
|
__m128i a0 = _mm256_castsi256_si128(itmp3);
|
|
|
|
__m128i a3 = _mm256_extractf128_si256(itmp4, 1);
|
|
|
|
__m128i a2 = _mm256_castsi256_si128(itmp4);
|
|
|
|
|
2014-02-20 18:04:00 +00:00
|
|
|
__m128i outshorts1 = _mm_packs_epi32(a0, a1);
|
|
|
|
__m128i outshorts2 = _mm_packs_epi32(a2, a3);
|
|
|
|
|
|
|
|
__m128i outbytes = _mm_packs_epi16(outshorts1, outshorts2);
|
2013-05-06 19:52:19 +00:00
|
|
|
|
|
|
|
_mm_storeu_si128 ((__m128i*)&outbuf[i*16], outbytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
#elif USE_SSE2
|
2015-12-07 19:37:32 +00:00
|
|
|
void convert_sse2(const float* inbuf, int8_t* outbuf,const unsigned int count)
|
2013-05-06 19:52:19 +00:00
|
|
|
{
|
|
|
|
const register __m128 mulme = _mm_set_ps( 127.0f, 127.0f, 127.0f, 127.0f );
|
|
|
|
__m128 itmp1,itmp2,itmp3,itmp4;
|
|
|
|
__m128i otmp1,otmp2,otmp3,otmp4;
|
|
|
|
|
|
|
|
__m128i outshorts1,outshorts2;
|
|
|
|
__m128i outbytes;
|
|
|
|
|
|
|
|
for(unsigned int i=0; i<count;i++){
|
|
|
|
|
|
|
|
itmp1 = _mm_mul_ps(_mm_loadu_ps(&inbuf[i*16+0]), mulme);
|
|
|
|
itmp2 = _mm_mul_ps(_mm_loadu_ps(&inbuf[i*16+4]), mulme);
|
|
|
|
itmp3 = _mm_mul_ps(_mm_loadu_ps(&inbuf[i*16+8]), mulme);
|
|
|
|
itmp4 = _mm_mul_ps(_mm_loadu_ps(&inbuf[i*16+12]), mulme);
|
|
|
|
|
|
|
|
otmp1 = _mm_cvtps_epi32(itmp1);
|
|
|
|
otmp2 = _mm_cvtps_epi32(itmp2);
|
|
|
|
otmp3 = _mm_cvtps_epi32(itmp3);
|
|
|
|
otmp4 = _mm_cvtps_epi32(itmp4);
|
|
|
|
|
2014-02-20 18:04:00 +00:00
|
|
|
outshorts1 = _mm_packs_epi32(otmp1, otmp2);
|
|
|
|
outshorts2 = _mm_packs_epi32(otmp3, otmp4);
|
2013-05-06 19:52:19 +00:00
|
|
|
|
2014-02-20 18:04:00 +00:00
|
|
|
outbytes = _mm_packs_epi16(outshorts1, outshorts2);
|
2013-05-06 19:52:19 +00:00
|
|
|
|
|
|
|
_mm_storeu_si128 ((__m128i*)&outbuf[i*16], outbytes);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2015-12-07 19:37:32 +00:00
|
|
|
void convert_default(float* inbuf, int8_t* outbuf,const unsigned int count)
|
2013-05-06 19:52:19 +00:00
|
|
|
{
|
|
|
|
for(unsigned int i=0; i<count;i++){
|
2014-02-20 18:04:00 +00:00
|
|
|
outbuf[i]= inbuf[i]*127;
|
2013-05-06 19:52:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-04-28 10:36:03 +00:00
|
|
|
int hackrf_sink_c::work( int noutput_items,
|
2013-05-08 19:37:30 +00:00
|
|
|
gr_vector_const_void_star &input_items,
|
|
|
|
gr_vector_void_star &output_items )
|
2013-04-28 10:36:03 +00:00
|
|
|
{
|
|
|
|
const gr_complex *in = (const gr_complex *) input_items[0];
|
|
|
|
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
std::unique_lock<std::mutex> lock(_buf_mutex);
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
while ( ! cb_has_room(&_cbuf) )
|
|
|
|
_buf_cond.wait( lock );
|
|
|
|
}
|
|
|
|
|
2015-12-07 19:37:32 +00:00
|
|
|
int8_t *buf = _buf + _buf_used;
|
2013-04-28 10:36:03 +00:00
|
|
|
unsigned int prev_buf_used = _buf_used;
|
|
|
|
|
2013-05-06 19:52:19 +00:00
|
|
|
unsigned int remaining = (BUF_LEN-_buf_used)/2; //complex
|
2013-04-28 10:36:03 +00:00
|
|
|
|
2013-05-06 19:52:19 +00:00
|
|
|
unsigned int count = std::min((unsigned int)noutput_items,remaining);
|
|
|
|
unsigned int sse_rem = count/8; // 8 complex = 16f==512bit for avx
|
|
|
|
unsigned int nosse_rem = count%8; // remainder
|
2013-04-28 10:36:03 +00:00
|
|
|
|
2013-05-06 19:52:19 +00:00
|
|
|
#ifdef USE_AVX
|
|
|
|
convert_avx((float*)in, buf, sse_rem);
|
|
|
|
convert_default((float*)(in+sse_rem*8), buf+(sse_rem*8*2), nosse_rem*2);
|
|
|
|
#elif USE_SSE2
|
|
|
|
convert_sse2((float*)in, buf, sse_rem);
|
|
|
|
convert_default((float*)(in+sse_rem*8), buf+(sse_rem*8*2), nosse_rem*2);
|
|
|
|
#else
|
|
|
|
convert_default((float*)in, buf, count*2);
|
|
|
|
#endif
|
2013-04-28 10:36:03 +00:00
|
|
|
|
2013-05-06 19:52:19 +00:00
|
|
|
_buf_used += (sse_rem*8+nosse_rem)*2;
|
|
|
|
int items_consumed = sse_rem*8+nosse_rem;
|
|
|
|
|
2013-05-08 18:39:24 +00:00
|
|
|
if((unsigned int)noutput_items >= remaining) {
|
2013-05-06 19:52:19 +00:00
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
std::unique_lock<std::mutex> lock(_buf_mutex);
|
2013-05-06 19:52:19 +00:00
|
|
|
|
|
|
|
if ( ! cb_push_back( &_cbuf, _buf ) ) {
|
|
|
|
_buf_used = prev_buf_used;
|
|
|
|
items_consumed = 0;
|
|
|
|
std::cerr << "O" << std::flush;
|
|
|
|
} else {
|
2013-05-08 19:37:30 +00:00
|
|
|
// std::cerr << "+" << std::flush;
|
2013-05-06 19:52:19 +00:00
|
|
|
_buf_used = 0;
|
|
|
|
}
|
|
|
|
}
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Tell runtime system how many input items we consumed on
|
|
|
|
// each input stream.
|
2013-05-08 18:25:23 +00:00
|
|
|
consume_each(items_consumed);
|
2013-04-28 10:36:03 +00:00
|
|
|
|
|
|
|
// Tell runtime system how many output items we produced.
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> hackrf_sink_c::get_devices()
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_devices();
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
size_t hackrf_sink_c::get_num_channels()
|
|
|
|
{
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::meta_range_t hackrf_sink_c::get_sample_rates()
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_sample_rates();
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-06-02 13:29:19 +00:00
|
|
|
double hackrf_sink_c::set_sample_rate( double rate )
|
2013-04-28 10:36:03 +00:00
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_sample_rate(rate);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::get_sample_rate()
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_sample_rate();
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::freq_range_t hackrf_sink_c::get_freq_range( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_freq_range(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::set_center_freq( double freq, size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_center_freq(freq, chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::get_center_freq( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_center_freq(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::set_freq_corr( double ppm, size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_freq_corr(ppm, chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::get_freq_corr( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_freq_corr(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::vector<std::string> hackrf_sink_c::get_gain_names( size_t chan )
|
|
|
|
{
|
2020-01-31 04:22:03 +00:00
|
|
|
return { "RF", "IF" };
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::gain_range_t hackrf_sink_c::get_gain_range( size_t chan )
|
|
|
|
{
|
|
|
|
return get_gain_range( "RF", chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
osmosdr::gain_range_t hackrf_sink_c::get_gain_range( const std::string & name, size_t chan )
|
|
|
|
{
|
|
|
|
if ( "RF" == name ) {
|
|
|
|
return osmosdr::gain_range_t( 0, 14, 14 );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( "IF" == name ) {
|
|
|
|
return osmosdr::gain_range_t( 0, 47, 1 );
|
|
|
|
}
|
|
|
|
|
|
|
|
return osmosdr::gain_range_t();
|
|
|
|
}
|
|
|
|
|
|
|
|
bool hackrf_sink_c::set_gain_mode( bool automatic, size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_gain_mode(automatic, chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
bool hackrf_sink_c::get_gain_mode( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_gain_mode(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::set_gain( double gain, size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_gain(gain, chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::set_gain( double gain, const std::string & name, size_t chan)
|
|
|
|
{
|
|
|
|
if ( "RF" == name ) {
|
|
|
|
return set_gain( gain, chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( "IF" == name ) {
|
|
|
|
return set_if_gain( gain, chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
return set_gain( gain, chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::get_gain( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_gain(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::get_gain( const std::string & name, size_t chan )
|
|
|
|
{
|
|
|
|
if ( "RF" == name ) {
|
|
|
|
return get_gain( chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( "IF" == name ) {
|
|
|
|
return _vga_gain;
|
|
|
|
}
|
|
|
|
|
|
|
|
return get_gain( chan );
|
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::set_if_gain( double gain, size_t chan )
|
|
|
|
{
|
2013-06-07 19:43:52 +00:00
|
|
|
int ret;
|
2013-04-28 10:36:03 +00:00
|
|
|
osmosdr::gain_range_t if_gains = get_gain_range( "IF", chan );
|
|
|
|
|
2020-01-26 23:48:59 +00:00
|
|
|
if (_dev.get()) {
|
2013-06-02 13:29:19 +00:00
|
|
|
double clip_gain = if_gains.clip( gain, true );
|
2013-04-28 10:36:03 +00:00
|
|
|
|
2020-01-26 23:48:59 +00:00
|
|
|
ret = hackrf_set_txvga_gain( _dev.get(), uint32_t(clip_gain) );
|
2013-06-07 19:43:52 +00:00
|
|
|
if ( HACKRF_SUCCESS == ret ) {
|
|
|
|
_vga_gain = clip_gain;
|
|
|
|
} else {
|
|
|
|
HACKRF_THROW_ON_ERROR( ret, HACKRF_FUNC_STR( "hackrf_set_txvga_gain", clip_gain ) )
|
|
|
|
}
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return _vga_gain;
|
|
|
|
}
|
|
|
|
|
2013-06-02 13:29:19 +00:00
|
|
|
double hackrf_sink_c::set_bb_gain( double gain, size_t chan )
|
2013-04-28 10:36:03 +00:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
std::vector< std::string > hackrf_sink_c::get_antennas( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_antennas(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string hackrf_sink_c::set_antenna( const std::string & antenna, size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_antenna(antenna, chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
std::string hackrf_sink_c::get_antenna( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_antenna(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::set_bandwidth( double bandwidth, size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::set_bandwidth(bandwidth, chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
double hackrf_sink_c::get_bandwidth( size_t chan )
|
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_bandwidth(chan);
|
2013-04-28 10:36:03 +00:00
|
|
|
}
|
|
|
|
|
2013-04-30 19:00:57 +00:00
|
|
|
osmosdr::freq_range_t hackrf_sink_c::get_bandwidth_range( size_t chan )
|
2013-04-28 10:36:03 +00:00
|
|
|
{
|
2020-01-26 23:48:59 +00:00
|
|
|
return hackrf_common::get_bandwidth_range(chan);
|
2013-04-10 18:42:43 +00:00
|
|
|
}
|