22 #include <QNetworkReply> 46 m_deviceAPI(deviceAPI),
47 m_variant(SDRPlayUndef),
51 m_deviceDescription("SDRPlay"),
56 m_fileSink =
new FileRecord(QString(
"test_%1.sdriq").
arg(m_deviceAPI->getDeviceUID()));
57 m_deviceAPI->setNbSourceStreams(1);
58 m_deviceAPI->addAncillarySink(m_fileSink);
60 m_networkManager =
new QNetworkAccessManager();
61 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
97 qCritical(
"SDRPlayInput::openDevice: could not allocate SampleFifo");
103 qCritical(
"SDRPlayInput::openDevice: could not open SDRPlay #%d: %s",
m_devNumber, strerror(errno));
115 if ((res = mirisdr_get_device_usb_strings(
m_devNumber, vendor, product, serial)) < 0)
117 qCritical(
"SDRPlayInput::openDevice: error accessing USB device");
122 qWarning(
"SDRPlayInput::openDevice: %s %s, SN: %s", vendor, product, serial);
125 if (QString(product) ==
"RSP1A") {
127 }
else if (QString(product) ==
"RSP2") {
133 qDebug(
"SDRPlayInput::openDevice: m_variant: %d", (
int)
m_variant);
149 char s12FormatString[] =
"336_S16";
151 if ((res = mirisdr_set_sample_format(
m_dev, s12FormatString)))
153 qCritical(
"SDRPlayInput::start: could not set sample format: rc: %d", res);
160 if ((res = mirisdr_set_sample_rate(
m_dev, sampleRate)))
162 qCritical(
"SDRPlayInput::start: could not set sample rate to %d: rc: %d", sampleRate, res);
167 char bulkFormatString[] =
"BULK";
169 if ((res = mirisdr_set_transfer(
m_dev, bulkFormatString)) < 0)
171 qCritical(
"SDRPlayInput::start: could not set USB Bulk mode: rc: %d", res);
176 if ((res = mirisdr_reset_buffer(
m_dev)) < 0)
178 qCritical(
"SDRPlayInput::start: could not reset USB EP buffers: %s", strerror(errno));
201 mirisdr_close(
m_dev);
290 qDebug() <<
"SDRPlayInput::handleMessage: MsgConfigureSDRPlay";
306 qDebug(
"SDRPlayInput::handleMessage: config error");
315 qDebug() <<
"SDRPlayInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
337 qDebug() <<
"SDRPlayInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
365 bool forceGainSetting =
false;
366 QList<QString> reverseAPIKeys;
367 QMutexLocker mutexLocker(&
m_mutex);
371 reverseAPIKeys.append(
"dcBlock");
377 reverseAPIKeys.append(
"iqCorrection");
385 reverseAPIKeys.append(
"tunerGainMode");
386 forceGainSetting =
true;
390 reverseAPIKeys.append(
"tunerGain");
393 reverseAPIKeys.append(
"lnaOn");
406 qDebug(
"SDRPlayInput::applySettings: could not set tuner gain");
414 lnaGain = mirisdr_get_mixbuffer_gain(
m_dev);
418 lnaGain = mirisdr_get_lna_gain(
m_dev);
423 mirisdr_get_mixer_gain(
m_dev),
424 mirisdr_get_baseband_gain(
m_dev),
425 mirisdr_get_tuner_gain(
m_dev)
437 bool anyChange =
false;
445 int r = mirisdr_set_mixbuffer_gain(
m_dev, settings.
m_lnaOn ? 0 : 1);
448 qDebug(
"SDRPlayInput::applySettings: could not set mixer buffer gain");
455 int r = mirisdr_set_lna_gain(
m_dev, settings.
m_lnaOn ? 0 : 1);
458 qDebug(
"SDRPlayInput::applySettings: could not set LNA gain");
468 reverseAPIKeys.append(
"mixerAmpOn");
475 qDebug(
"SDRPlayInput::applySettings: could not set mixer gain");
484 reverseAPIKeys.append(
"basebandGain");
491 qDebug(
"SDRPlayInput::applySettings: could not set mixer gain");
503 lnaGain = mirisdr_get_mixbuffer_gain(
m_dev);
505 lnaGain = mirisdr_get_lna_gain(
m_dev);
510 mirisdr_get_mixer_gain(
m_dev),
511 mirisdr_get_baseband_gain(
m_dev),
512 mirisdr_get_tuner_gain(
m_dev)
523 reverseAPIKeys.append(
"log2Decim");
528 qDebug() <<
"SDRPlayInput::applySettings: set decimation to " << (1<<settings.
m_log2Decim);
534 reverseAPIKeys.append(
"fcPos");
539 qDebug() <<
"SDRPlayInput: set fc pos (enum) to " << (int) settings.
m_fcPos;
544 reverseAPIKeys.append(
"centerFrequency");
547 reverseAPIKeys.append(
"LOppmTenths");
561 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
564 forwardChange =
true;
569 qDebug() <<
"SDRPlayInput::applySettings: center freq: " << settings.
m_centerFrequency <<
" Hz";
576 reverseAPIKeys.append(
"bandwidthIndex");
578 int r = mirisdr_set_bandwidth(
m_dev, bandwidth);
581 qCritical(
"SDRPlayInput::applySettings: set bandwidth %d failed: rc: %d", bandwidth, r);
583 qDebug(
"SDRPlayInput::applySettings: bandwidth set to %d", bandwidth);
589 reverseAPIKeys.append(
"ifFrequencyIndex");
591 int r = mirisdr_set_if_freq(
m_dev, iFFrequency);
594 qCritical(
"SDRPlayInput::applySettings: set IF frequency to %d failed: rc: %d", iFFrequency, r);
596 qDebug(
"SDRPlayInput::applySettings: IF frequency set to %d", iFFrequency);
627 int r = mirisdr_set_center_freq(
m_dev, static_cast<uint32_t>(freq_hz));
631 qWarning(
"SDRPlayInput::setDeviceCenterFrequency: could not frequency to %llu Hz", freq_hz);
636 qWarning(
"SDRPlayInput::setDeviceCenterFrequency: frequency set to %llu Hz", freq_hz);
643 QString& errorMessage)
653 QString& errorMessage)
671 QString& errorMessage)
682 const QStringList& deviceSettingsKeys,
684 QString& errorMessage)
689 if (deviceSettingsKeys.contains(
"centerFrequency")) {
692 if (deviceSettingsKeys.contains(
"tunerGain")) {
695 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
698 if (deviceSettingsKeys.contains(
"frequencyBandIndex")) {
701 if (deviceSettingsKeys.contains(
"ifFrequencyIndex")) {
704 if (deviceSettingsKeys.contains(
"bandwidthIndex")) {
707 if (deviceSettingsKeys.contains(
"devSampleRateIndex")) {
710 if (deviceSettingsKeys.contains(
"log2Decim")) {
713 if (deviceSettingsKeys.contains(
"fcPos"))
716 fcPos = fcPos < 0 ? 0 : fcPos > 2 ? 2 : fcPos;
719 if (deviceSettingsKeys.contains(
"dcBlock")) {
722 if (deviceSettingsKeys.contains(
"iqCorrection")) {
725 if (deviceSettingsKeys.contains(
"tunerGainMode")) {
728 if (deviceSettingsKeys.contains(
"lnaOn")) {
731 if (deviceSettingsKeys.contains(
"mixerAmpOn")) {
734 if (deviceSettingsKeys.contains(
"basebandGain")) {
737 if (deviceSettingsKeys.contains(
"fileRecordName")) {
740 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
743 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
746 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
749 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
804 QString& errorMessage)
861 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
864 if (deviceSettingsKeys.contains(
"tunerGain") || force) {
867 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
870 if (deviceSettingsKeys.contains(
"frequencyBandIndex") || force) {
873 if (deviceSettingsKeys.contains(
"ifFrequencyIndex") || force) {
876 if (deviceSettingsKeys.contains(
"bandwidthIndex") || force) {
879 if (deviceSettingsKeys.contains(
"devSampleRateIndex") || force) {
882 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
885 if (deviceSettingsKeys.contains(
"fcPos") || force) {
888 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
891 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
894 if (deviceSettingsKeys.contains(
"tunerGainMode") || force) {
897 if (deviceSettingsKeys.contains(
"lnaOn") || force) {
900 if (deviceSettingsKeys.contains(
"mixerAmpOn") || force) {
903 if (deviceSettingsKeys.contains(
"basebandGain") || force) {
906 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
910 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
915 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
917 QBuffer *buffer=
new QBuffer();
918 buffer->open((QBuffer::ReadWrite));
919 buffer->write(swgDeviceSettings->
asJson().toUtf8());
925 delete swgDeviceSettings;
935 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
940 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
942 QBuffer *buffer=
new QBuffer();
943 buffer->open((QBuffer::ReadWrite));
944 buffer->write(swgDeviceSettings->
asJson().toUtf8());
953 delete swgDeviceSettings;
958 QNetworkReply::NetworkError replyError = reply->error();
962 qWarning() <<
"SDRPlayInput::networkManagerFinished:" 963 <<
" error(" << (int) replyError
964 <<
"): " << replyError
965 <<
": " << reply->errorString();
969 QString answer = reply->readAll();
971 qDebug(
"SDRPlayInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
999 if (rate_index < m_nb_rates)
1001 return m_rates[rate_index];
1011 for (
unsigned int i=0;
i < m_nb_rates;
i++)
1013 if (rate == m_rates[
i])
1042 if (bandwidth_index < m_nb_bw)
1044 return m_bw[bandwidth_index];
1054 for (
unsigned int i=0;
i < m_nb_bw;
i++)
1056 if (bandwidth == m_bw[
i])
1081 if (if_index < m_nb_if)
1083 return m_if[if_index];
1093 for (
unsigned int i=0;
i < m_nb_if;
i++)
1148 if (band_index < m_nb_bands)
1150 return QString(m_bandName[band_index]);
1154 return QString(m_bandName[0]);
1160 if (band_index < m_nb_bands)
1162 return m_bandLow[band_index];
1166 return m_bandLow[0];
1172 if (band_index < m_nb_bands)
1174 return m_bandHigh[band_index];
1178 return m_bandHigh[0];
static unsigned int getNbRates()
uint32_t m_ifFrequencyIndex
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
void setFileRecordName(QString *file_record_name)
void setSdrPlayReport(SWGSDRPlayReport *sdr_play_report)
void setIntermediateFrequencies(QList< SWGFrequency *> *intermediate_frequencies)
void setBandwidths(QList< SWGBandwidth *> *bandwidths)
uint16_t m_reverseAPIPort
static qint64 calculateDeviceCenterFrequency(quint64 centerFrequency, qint64 transverterDeltaFrequency, int log2Decim, fcPos_t fcPos, quint32 devSampleRate, FrequencyShiftScheme frequencyShiftScheme, bool transverterMode=false)
QString * getFileRecordName()
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
QList< SWGSampleRate * > * getSampleRates()
void setReverseApiPort(qint32 reverse_api_port)
void setFileName(const QString &filename)
void setIqCorrection(qint32 iq_correction)
uint getDeviceUID() const
Return the current device engine unique ID.
static unsigned int m_rates[m_nb_rates]
void setDcBlock(qint32 dc_block)
static unsigned int m_bandHigh[m_nb_bands]
static unsigned int m_if[m_nb_if]
void setTunerGain(qint32 tuner_gain)
SWGSDRPlaySettings * getSdrPlaySettings()
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
void setFrequencyBands(QList< SWGFrequencyBand *> *frequency_bands)
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
qint32 getReverseApiPort()
static unsigned int getNbBands()
static const unsigned int m_nb_bw
static const unsigned int m_nb_if
static unsigned int getNbBandwidths()
qint32 getDevSampleRateIndex()
static const char * m_bandName[m_nb_bands]
void setBasebandGain(qint32 baseband_gain)
void setSdrPlaySettings(SWGSDRPlaySettings *sdr_play_settings)
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
static unsigned int getNbIFs()
void setIfFrequencyIndex(qint32 if_frequency_index)
static unsigned int getRateIndex(unsigned int rate)
qint32 getBandwidthIndex()
void setOriginatorIndex(qint32 originator_index)
QString * getReverseApiAddress()
SWGSDRPlayReport * getSdrPlayReport()
SampleSinkFifo m_sampleFifo
MessageQueue * getMessageQueueToGUI()
void setUseReverseApi(qint32 use_reverse_api)
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
virtual bool handleMessage(const Message &message)
Processing of a message. Returns true if message has actually been processed.
static const unsigned int m_nb_bands
void setTunerGainMode(qint32 tuner_gain_mode)
void setLnaOn(qint32 lna_on)
int getDeviceSetIndex() const
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
QString m_reverseAPIAddress
void genUniqueFileName(uint deviceUID, int istream=-1)
QByteArray serialize() const
static unsigned int m_bw[m_nb_bw]
void setLog2Decimation(unsigned int log2_decim)
void setLog2Decim(qint32 log2_decim)
void setFrequencyBandIndex(qint32 frequency_band_index)
qint32 getUseReverseApi()
static bool match(const Message *message)
qint32 getFrequencyBandIndex()
uint64_t m_centerFrequency
void setCenterFrequency(qint32 center_frequency)
static unsigned int getBandLow(unsigned int band_index)
static unsigned int getBandwidth(unsigned int bandwidth_index)
void removeAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Removes it.
static unsigned int m_bandLow[m_nb_bands]
uint32_t m_frequencyBandIndex
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void setBandwidthIndex(qint32 bandwidth_index)
QList< SWGBandwidth * > * getBandwidths()
void setFcPos(qint32 fc_pos)
void getDeviceEngineStateStr(QString &state)
static const unsigned int m_nb_rates
uint32_t m_bandwidthIndex
static unsigned int getBandwidthIndex(unsigned int bandwidth)
bool deserialize(const QByteArray &data)
static unsigned int getIFIndex(unsigned int iff)
QList< SWGFrequency * > * getIntermediateFrequencies()
void setLOppmTenths(qint32 l_oppm_tenths)
QList< SWGFrequencyBand * > * getFrequencyBands()
void setDevSampleRateIndex(qint32 dev_sample_rate_index)
static unsigned int getRate(unsigned int rate_index)
static unsigned int getIF(unsigned int if_index)
static unsigned int getBandHigh(unsigned int band_index)
void setSampleRates(QList< SWGSampleRate *> *sample_rates)
qint32 getIfFrequencyIndex()
static QString getBandName(unsigned int band_index)
qint32 getCenterFrequency()
qint32 getReverseApiDeviceIndex()
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
uint16_t m_reverseAPIDeviceIndex
uint32_t m_devSampleRateIndex
uint32_t getSamplingDeviceSequence() const
void setDirection(qint32 direction)
void setMixerAmpOn(qint32 mixer_amp_on)
void setReverseApiAddress(QString *reverse_api_address)
void setDeviceHwType(QString *device_hw_type)
qint32 getTunerGainMode()