sdrangel/plugins/samplesource/fcd/fcdsource.cpp

96 wiersze
2.0 KiB
C++
Czysty Zwykły widok Historia

2014-11-30 21:59:06 +00:00
/* (C)2015 John Greb
2014-12-01 19:49:00 +00: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 21:59:06 +00: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 19:00:12 +00:00
#include "fcdinput.h"
2014-11-30 21:59:06 +00:00
#include "fcdthread.h"
2014-12-01 19:49:00 +00:00
#include "qthid.h"
2014-11-30 21:59:06 +00:00
bool FCDThread::OpenSource(const char* cardname)
{
2014-12-02 16:57:42 +00:00
bool fail = false;
2014-12-01 16:56:27 +00:00
snd_pcm_hw_params_t* params;
2014-11-30 21:59:06 +00:00
//fcd_rate = FCDPP_RATE;
//fcd_channels =2;
//fcd_format = SND_PCM_SFMT_U16_LE;
2014-12-01 16:56:27 +00:00
snd_pcm_stream_t fcd_stream = SND_PCM_STREAM_CAPTURE;
2014-11-30 21:59:06 +00:00
if (fcd_handle)
return false;
2014-12-01 16:56:27 +00:00
if ( snd_pcm_open( &fcd_handle, cardname, fcd_stream, 0 ) < 0 )
2014-11-30 21:59:06 +00:00
return false;
2014-12-01 16:56:27 +00:00
snd_pcm_hw_params_alloca(&params);
if ( snd_pcm_hw_params_any(fcd_handle, params) < 0 )
2014-12-02 16:57:42 +00: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 16:56:27 +00:00
qCritical("Funcube Dongle stream start failed");
2014-12-02 16:57:42 +00:00
snd_pcm_close( fcd_handle );
return false;
} else {
qDebug("Funcube stream started");
}
2014-11-30 21:59:06 +00:00
return true;
}
void FCDThread::CloseSource()
{
if (fcd_handle)
snd_pcm_close( fcd_handle );
fcd_handle = NULL;
}
2014-12-02 19:00:12 +00:00
void FCDInput::set_center_freq(double freq)
2014-11-30 21:59:06 +00:00
{
2014-12-01 19:49:00 +00:00
if (fcdAppSetFreq(freq) == FCD_MODE_NONE)
2014-12-02 14:23:21 +00:00
qDebug("No FCD HID found for frquency change");
}
2014-12-02 19:00:12 +00:00
void FCDInput::set_bias_t(bool on)
2014-12-02 14:23:21 +00:00
{
quint8 cmd = on ? 1 : 0;
fcdAppSetParam(FCD_CMD_APP_SET_BIAS_TEE, &cmd, 1);
}
2014-12-02 19:00:12 +00:00
void FCDInput::set_lna_gain(bool on)
2014-12-02 14:23:21 +00:00
{
quint8 cmd = on ? 1 : 0;
fcdAppSetParam(FCD_CMD_APP_SET_LNA_GAIN, &cmd, 1);
2014-11-30 21:59:06 +00:00
}
2014-12-01 16:56:27 +00:00
int FCDThread::work(int n_items)
2014-11-30 21:59:06 +00:00
{
int l;
SampleVector::iterator it;
void *out;
it = m_convertBuffer.begin();
out = (void *)&it[0];
2014-12-01 16:56:27 +00:00
l = snd_pcm_mmap_readi(fcd_handle, out, (snd_pcm_uframes_t)n_items);
2014-11-30 21:59:06 +00:00
if (l > 0)
m_sampleFifo->write(it, it + l);
2014-12-02 14:23:21 +00:00
if (l == -EPIPE) {
qDebug("FCD: Overrun detected");
return 0;
}
2014-12-01 16:56:27 +00:00
return l;
2014-11-30 21:59:06 +00:00
}