1
0
mirror of https://github.com/f4exb/sdrangel.git synced 2024-11-08 17:46:03 -05:00
sdrangel/plugins/samplesource/fcd/fcdsource.cpp

96 lines
2.0 KiB
C++
Raw Normal View History

2014-11-30 16:59:06 -05:00
/* (C)2015 John Greb
2014-12-01 14:49:00 -05:00
*
* Funcube Dongle command line interface
* Copyright 2011 David Pello EA1IDZ
* Copyright 2011 Pieter-Tjerk de Boer PA3FWM
* Copyright 2012-2014 Alexandru Csete OZ9AEC
*
2014-11-30 16:59:06 -05:00
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public Licence version 3.
*/
2014-12-02 14:00:12 -05:00
#include "fcdinput.h"
2014-11-30 16:59:06 -05:00
#include "fcdthread.h"
2014-12-01 14:49:00 -05:00
#include "qthid.h"
2014-11-30 16:59:06 -05:00
bool FCDThread::OpenSource(const char* cardname)
{
2014-12-02 11:57:42 -05:00
bool fail = false;
2014-12-01 11:56:27 -05:00
snd_pcm_hw_params_t* params;
2014-11-30 16:59:06 -05:00
//fcd_rate = FCDPP_RATE;
//fcd_channels =2;
//fcd_format = SND_PCM_SFMT_U16_LE;
2014-12-01 11:56:27 -05:00
snd_pcm_stream_t fcd_stream = SND_PCM_STREAM_CAPTURE;
2014-11-30 16:59:06 -05:00
if (fcd_handle)
return false;
2014-12-01 11:56:27 -05:00
if ( snd_pcm_open( &fcd_handle, cardname, fcd_stream, 0 ) < 0 )
2014-11-30 16:59:06 -05:00
return false;
2014-12-01 11:56:27 -05:00
snd_pcm_hw_params_alloca(&params);
if ( snd_pcm_hw_params_any(fcd_handle, params) < 0 )
2014-12-02 11:57:42 -05:00
fail = true;
else if ( snd_pcm_hw_params(fcd_handle, params) < 0 ) {
fail = true;
// TODO: check actual samplerate, may be crippled firmware
} else {
if ( snd_pcm_start(fcd_handle) < 0 )
fail = true;
}
if (fail) {
2014-12-01 11:56:27 -05:00
qCritical("Funcube Dongle stream start failed");
2014-12-02 11:57:42 -05:00
snd_pcm_close( fcd_handle );
return false;
} else {
qDebug("Funcube stream started");
}
2014-11-30 16:59:06 -05:00
return true;
}
void FCDThread::CloseSource()
{
if (fcd_handle)
snd_pcm_close( fcd_handle );
fcd_handle = NULL;
}
2014-12-02 14:00:12 -05:00
void FCDInput::set_center_freq(double freq)
2014-11-30 16:59:06 -05:00
{
2014-12-01 14:49:00 -05:00
if (fcdAppSetFreq(freq) == FCD_MODE_NONE)
2014-12-02 09:23:21 -05:00
qDebug("No FCD HID found for frquency change");
}
2014-12-02 14:00:12 -05:00
void FCDInput::set_bias_t(bool on)
2014-12-02 09:23:21 -05:00
{
quint8 cmd = on ? 1 : 0;
fcdAppSetParam(FCD_CMD_APP_SET_BIAS_TEE, &cmd, 1);
}
2014-12-02 14:00:12 -05:00
void FCDInput::set_lna_gain(bool on)
2014-12-02 09:23:21 -05:00
{
quint8 cmd = on ? 1 : 0;
fcdAppSetParam(FCD_CMD_APP_SET_LNA_GAIN, &cmd, 1);
2014-11-30 16:59:06 -05:00
}
2014-12-01 11:56:27 -05:00
int FCDThread::work(int n_items)
2014-11-30 16:59:06 -05:00
{
int l;
SampleVector::iterator it;
void *out;
it = m_convertBuffer.begin();
out = (void *)&it[0];
2014-12-01 11:56:27 -05:00
l = snd_pcm_mmap_readi(fcd_handle, out, (snd_pcm_uframes_t)n_items);
2014-11-30 16:59:06 -05:00
if (l > 0)
m_sampleFifo->write(it, it + l);
2014-12-02 09:23:21 -05:00
if (l == -EPIPE) {
qDebug("FCD: Overrun detected");
return 0;
}
2014-12-01 11:56:27 -05:00
return l;
2014-11-30 16:59:06 -05:00
}