23 #include <QNetworkReply> 53 m_deviceAPI(deviceAPI),
57 m_deviceDescription(),
105 qCritical(
"RTLSDRInput::openDevice: Could not allocate SampleFifo");
113 qCritical(
"RTLSDRInput::openDevice: could not get RTLSDR serial number");
117 if ((res = rtlsdr_open(&
m_dev, device)) < 0)
119 qCritical(
"RTLSDRInput::openDevice: could not open RTLSDR #%d: %s", device, strerror(errno));
127 if ((res = rtlsdr_get_usb_strings(
m_dev, vendor, product, serial)) < 0)
129 qCritical(
"RTLSDRInput::openDevice: error accessing USB device");
134 qInfo(
"RTLSDRInput::openDevice: open: %s %s, SN: %s", vendor, product, serial);
137 if ((res = rtlsdr_set_sample_rate(
m_dev, 1152000)) < 0)
139 qCritical(
"RTLSDRInput::openDevice: could not set sample rate: 1024k S/s");
144 if ((res = rtlsdr_set_tuner_gain_mode(
m_dev, 1)) < 0)
146 qCritical(
"RTLSDRInput::openDevice: error setting tuner gain mode");
151 if ((res = rtlsdr_set_agc_mode(
m_dev, 0)) < 0)
153 qCritical(
"RTLSDRInput::openDevice: error setting agc mode");
158 numberOfGains = rtlsdr_get_tuner_gains(
m_dev, NULL);
160 if (numberOfGains < 0)
162 qCritical(
"RTLSDRInput::openDevice: error getting number of gain values supported");
171 qCritical(
"RTLSDRInput::openDevice: error getting gain values");
177 qDebug() <<
"RTLSDRInput::openDevice: " <<
m_gains.size() <<
"gains";
180 if ((res = rtlsdr_reset_buffer(
m_dev)) < 0)
182 qCritical(
"RTLSDRInput::openDevice: could not reset USB EP buffers: %s", strerror(errno));
197 QMutexLocker mutexLocker(&
m_mutex);
212 mutexLocker.unlock();
233 QMutexLocker mutexLocker(&
m_mutex);
308 qDebug() <<
"RTLSDRInput::handleMessage: MsgConfigureRTLSDR";
314 qDebug(
"RTLSDRInput::handleMessage: config error");
322 qDebug() <<
"RTLSDRInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
344 qDebug() <<
"RTLSDRInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
371 bool forwardChange =
false;
372 QList<QString> reverseAPIKeys;
376 reverseAPIKeys.append(
"agc");
378 if (rtlsdr_set_agc_mode(
m_dev, settings.
m_agc ? 1 : 0) < 0) {
379 qCritical(
"RTLSDRInput::applySettings: could not set AGC mode %s", settings.
m_agc ?
"on" :
"off");
381 qDebug(
"RTLSDRInput::applySettings: AGC mode %s", settings.
m_agc ?
"on" :
"off");
387 reverseAPIKeys.append(
"dcBlock");
388 reverseAPIKeys.append(
"iqImbalance");
390 qDebug(
"RTLSDRInput::applySettings: corrections: DC block: %s IQ imbalance: %s",
397 reverseAPIKeys.append(
"loPpmCorrection");
402 qCritical(
"RTLSDRInput::applySettings: could not set LO ppm correction: %d", settings.
m_loPpmCorrection);
404 qDebug(
"RTLSDRInput::applySettings: LO ppm correction set to: %d", settings.
m_loPpmCorrection);
411 reverseAPIKeys.append(
"devSampleRate");
412 forwardChange =
true;
418 qCritical(
"RTLSDRInput::applySettings: could not set sample rate: %d", settings.
m_devSampleRate);
426 qDebug(
"RTLSDRInput::applySettings: sample rate set to %d", settings.
m_devSampleRate);
433 reverseAPIKeys.append(
"log2Decim");
434 forwardChange =
true;
440 qDebug(
"RTLSDRInput::applySettings: log2decim set to %d", settings.
m_log2Decim);
445 reverseAPIKeys.append(
"fcPos");
451 qDebug() <<
"RTLSDRInput::applySettings: set fc pos (enum) to " << (int) settings.
m_fcPos;
455 reverseAPIKeys.append(
"centerFrequency");
458 reverseAPIKeys.append(
"devSampleRate");
461 reverseAPIKeys.append(
"transverterMode");
464 reverseAPIKeys.append(
"transverterDeltaFrequency");
480 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
483 forwardChange =
true;
487 if (rtlsdr_set_center_freq(
m_dev, deviceCenterFrequency) != 0) {
488 qWarning(
"RTLSDRInput::applySettings: rtlsdr_set_center_freq(%lld) failed", deviceCenterFrequency);
490 qDebug(
"RTLSDRInput::applySettings: rtlsdr_set_center_freq(%lld)", deviceCenterFrequency);
497 reverseAPIKeys.append(
"noModMode");
498 qDebug() <<
"RTLSDRInput::applySettings: set noModMode to " << settings.
m_noModMode;
509 reverseAPIKeys.append(
"lowSampleRate");
514 reverseAPIKeys.append(
"rfBandwidth");
529 reverseAPIKeys.append(
"offsetTuning");
534 qCritical(
"RTLSDRInput::applySettings: could not set offset tuning to %s", settings.
m_offsetTuning ?
"on" :
"off");
536 qDebug(
"RTLSDRInput::applySettings: offset tuning set to %s", settings.
m_offsetTuning ?
"on" :
"off");
543 reverseAPIKeys.append(
"gain");
547 if (rtlsdr_set_tuner_gain(
m_dev, settings.
m_gain) != 0) {
548 qCritical(
"RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() failed");
550 qDebug(
"RTLSDRInput::applySettings: rtlsdr_set_tuner_gain() to %d", settings.
m_gain);
579 rtlsdr_set_direct_sampling(
m_dev, on);
584 QString& errorMessage)
595 const QStringList& deviceSettingsKeys,
597 QString& errorMessage)
602 if (deviceSettingsKeys.contains(
"agc")) {
605 if (deviceSettingsKeys.contains(
"centerFrequency")) {
608 if (deviceSettingsKeys.contains(
"dcBlock")) {
611 if (deviceSettingsKeys.contains(
"devSampleRate")) {
614 if (deviceSettingsKeys.contains(
"fcPos")) {
617 if (deviceSettingsKeys.contains(
"gain")) {
620 if (deviceSettingsKeys.contains(
"iqImbalance")) {
623 if (deviceSettingsKeys.contains(
"loPpmCorrection")) {
626 if (deviceSettingsKeys.contains(
"log2Decim")) {
629 if (deviceSettingsKeys.contains(
"lowSampleRate")) {
632 if (deviceSettingsKeys.contains(
"noModMode")) {
635 if (deviceSettingsKeys.contains(
"offsetTuning")) {
638 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency")) {
641 if (deviceSettingsKeys.contains(
"transverterMode")) {
644 if (deviceSettingsKeys.contains(
"rfBandwidth")) {
647 if (deviceSettingsKeys.contains(
"fileRecordName")) {
650 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
653 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
656 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
659 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
678 qDebug(
"RTLSDRInput::webapiFormatDeviceSettings: m_lowSampleRate: %s", settings.
m_lowSampleRate ?
"true" :
"false");
715 QString& errorMessage)
725 QString& errorMessage)
743 QString& errorMessage)
756 for (std::vector<int>::const_iterator it =
getGains().begin(); it !=
getGains().end(); ++it)
774 if (deviceSettingsKeys.contains(
"agc") || force) {
777 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
780 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
783 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
786 if (deviceSettingsKeys.contains(
"fcPos") || force) {
789 if (deviceSettingsKeys.contains(
"gain") || force) {
792 if (deviceSettingsKeys.contains(
"iqImbalance") || force) {
795 if (deviceSettingsKeys.contains(
"loPpmCorrection") || force) {
798 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
801 if (deviceSettingsKeys.contains(
"lowSampleRate") || force) {
804 if (deviceSettingsKeys.contains(
"noModMode") || force) {
807 if (deviceSettingsKeys.contains(
"offsetTuning") || force) {
810 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency") || force) {
813 if (deviceSettingsKeys.contains(
"transverterMode") || force) {
816 if (deviceSettingsKeys.contains(
"rfBandwidth") || force) {
819 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
823 QString channelSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
828 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
830 QBuffer *buffer=
new QBuffer();
831 buffer->open((QBuffer::ReadWrite));
832 buffer->write(swgDeviceSettings->
asJson().toUtf8());
838 delete swgDeviceSettings;
848 QString channelSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
853 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
855 QBuffer *buffer=
new QBuffer();
856 buffer->open((QBuffer::ReadWrite));
857 buffer->write(swgDeviceSettings->
asJson().toUtf8());
866 delete swgDeviceSettings;
871 QNetworkReply::NetworkError replyError = reply->error();
875 qWarning() <<
"TestSourceInput::networkManagerFinished:" 876 <<
" error(" << (int) replyError
877 <<
"): " << replyError
878 <<
": " << reply->errorString();
882 QString answer = reply->readAll();
884 qDebug(
"RTLSDRInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
void setDcBlock(qint32 dc_block)
qint32 getReverseApiDeviceIndex()
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
void setSamplerate(int samplerate)
void setLowSampleRate(qint32 low_sample_rate)
static qint64 calculateDeviceCenterFrequency(quint64 centerFrequency, qint64 transverterDeltaFrequency, int log2Decim, fcPos_t fcPos, quint32 devSampleRate, FrequencyShiftScheme frequencyShiftScheme, bool transverterMode=false)
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
QList< SWGGain * > * getGains()
void setFileName(const QString &filename)
uint getDeviceUID() const
Return the current device engine unique ID.
void setNbSourceStreams(uint32_t nbSourceStreams)
qint32 getDevSampleRate()
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
QByteArray serialize() const
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
SWGRtlSdrSettings * getRtlSdrSettings()
void setDevSampleRate(qint32 dev_sample_rate)
void setOffsetTuning(qint32 offset_tuning)
void setTransverterDeltaFrequency(qint64 transverter_delta_frequency)
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
QString * getFileRecordName()
void setIqImbalance(qint32 iq_imbalance)
void setOriginatorIndex(qint32 originator_index)
qint32 getTransverterMode()
SampleSinkFifo m_sampleFifo
void setNoModMode(qint32 no_mod_mode)
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.
QString * getReverseApiAddress()
void setLog2Decimation(unsigned int log2_decim)
uint16_t m_reverseAPIDeviceIndex
uint16_t m_reverseAPIPort
int getDeviceSetIndex() const
void setGains(QList< SWGGain *> *gains)
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
void addAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Adds a sink to receive full baseband and that is not a channel (e.g. spectrum)
void genUniqueFileName(uint deviceUID, int istream=-1)
void setReverseApiAddress(QString *reverse_api_address)
void setRtlSdrReport(SWGRtlSdrReport *rtl_sdr_report)
static bool match(const Message *message)
void removeAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Removes it.
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
qint32 getLowSampleRate()
quint32 m_rfBandwidth
RF filter bandwidth in Hz.
qint32 getReverseApiPort()
qint64 getTransverterDeltaFrequency()
qint64 getCenterFrequency()
void setRtlSdrSettings(SWGRtlSdrSettings *rtl_sdr_settings)
void getDeviceEngineStateStr(QString &state)
void setReverseApiPort(qint32 reverse_api_port)
const QString & getSamplingDeviceSerial() const
qint32 getLoPpmCorrection()
void setCenterFrequency(qint64 center_frequency)
QString m_reverseAPIAddress
qint32 getUseReverseApi()
void setUseReverseApi(qint32 use_reverse_api)
void setFileRecordName(QString *file_record_name)
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
void setTransverterMode(qint32 transverter_mode)
qint64 m_transverterDeltaFrequency
void setGain(qint32 gain)
SWGRtlSdrReport * getRtlSdrReport()
void setRfBandwidth(qint32 rf_bandwidth)
void setFcPos(qint32 fc_pos)
quint64 m_centerFrequency
bool deserialize(const QByteArray &data)
void setLoPpmCorrection(qint32 lo_ppm_correction)
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
void setLog2Decim(qint32 log2_decim)
void setDirection(qint32 direction)
void setDeviceHwType(QString *device_hw_type)