23 #include <QNetworkReply> 49 m_deviceAPI(deviceAPI),
53 m_deviceDescription(
"Airspy"),
93 rc = (airspy_error) airspy_init();
95 if (rc != AIRSPY_SUCCESS)
97 qCritical(
"AirspyInput::start: failed to initiate Airspy library %s", airspy_error_name(rc));
102 qCritical(
"AirspyInput::start: could not allocate SampleFifo");
110 qCritical(
"AirspyInput::start: could not open Airspy #%d", device);
114 #ifdef LIBAIRSPY_DEFAULT_RATES 115 qDebug(
"AirspyInput::start: detault rates");
123 airspy_get_samplerates(
m_dev, &nbSampleRates, 0);
125 sampleRates =
new uint32_t[nbSampleRates];
127 airspy_get_samplerates(
m_dev, sampleRates, nbSampleRates);
129 if (nbSampleRates == 0)
131 qCritical(
"AirspyInput::start: could not obtain Airspy sample rates");
136 qDebug(
"AirspyInput::start: %d sample rates", nbSampleRates);
141 for (
unsigned int i=0;
i<nbSampleRates;
i++)
144 qDebug(
"AirspyInput::start: sampleRates[%d] = %u Hz", i, sampleRates[i]);
147 delete[] sampleRates;
153 rc = (airspy_error) airspy_set_sample_type(
m_dev, AIRSPY_SAMPLE_INT16_IQ);
155 if (rc != AIRSPY_SUCCESS)
157 qCritical(
"AirspyInput::start: could not set sample type to INT16_IQ");
171 QMutexLocker mutexLocker(&
m_mutex);
186 mutexLocker.unlock();
190 qDebug(
"AirspyInput::startInput: started");
200 airspy_stop_rx(
m_dev);
211 qDebug(
"AirspyInput::stop");
212 QMutexLocker mutexLocker(&
m_mutex);
287 qDebug() <<
"AirspyInput::handleMessage: MsgConfigureAirspy";
293 qDebug(
"AirspyInput::handleMessage: Airspy config error");
301 qDebug() <<
"AirspyInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
324 qDebug() <<
"AirspyInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
354 airspy_error rc = (airspy_error) airspy_set_freq(
m_dev, static_cast<uint32_t>(freq_hz));
356 if (rc != AIRSPY_SUCCESS)
358 qWarning(
"AirspyInput::setDeviceCenterFrequency: could not frequency to %llu Hz", freq_hz);
362 qDebug(
"AirspyInput::setDeviceCenterFrequency: frequency set to %llu Hz", freq_hz);
368 QMutexLocker mutexLocker(&
m_mutex);
370 bool forwardChange =
false;
371 airspy_error rc = AIRSPY_ERROR_OTHER;
372 QList<QString> reverseAPIKeys;
374 qDebug() <<
"AirspyInput::applySettings";
377 reverseAPIKeys.append(
"dcBlock");
380 reverseAPIKeys.append(
"iqCorrection");
391 reverseAPIKeys.append(
"devSampleRateIndex");
392 forwardChange =
true;
398 if (rc != AIRSPY_SUCCESS)
412 reverseAPIKeys.append(
"log2Decim");
413 forwardChange =
true;
418 qDebug() <<
"AirspyInput: set decimation to " << (1<<settings.
m_log2Decim);
423 reverseAPIKeys.append(
"centerFrequency");
426 reverseAPIKeys.append(
"LOppmTenths");
429 reverseAPIKeys.append(
"fcPos");
432 reverseAPIKeys.append(
"transverterMode");
435 reverseAPIKeys.append(
"transverterDeltaFrequency");
451 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
458 forwardChange =
true;
466 qDebug() <<
"AirspyInput: set fc pos (enum) to " << (int) settings.
m_fcPos;
472 reverseAPIKeys.append(
"lnaGain");
476 rc = (airspy_error) airspy_set_lna_gain(
m_dev, settings.
m_lnaGain);
478 if (rc != AIRSPY_SUCCESS) {
479 qDebug(
"AirspyInput::applySettings: airspy_set_lna_gain failed: %s", airspy_error_name(rc));
481 qDebug() <<
"AirspyInput:applySettings: LNA gain set to " << settings.
m_lnaGain;
488 reverseAPIKeys.append(
"lnaAGC");
491 rc = (airspy_error) airspy_set_lna_agc(
m_dev, (settings.
m_lnaAGC ? 1 : 0));
494 if (rc != AIRSPY_SUCCESS) {
495 qDebug(
"AirspyInput::applySettings: airspy_set_lna_agc failed: %s", airspy_error_name(rc));
497 qDebug() <<
"AirspyInput:applySettings: LNA AGC set to " << settings.
m_lnaAGC;
503 reverseAPIKeys.append(
"mixerGain");
509 if (rc != AIRSPY_SUCCESS) {
510 qDebug(
"AirspyInput::applySettings: airspy_set_mixer_gain failed: %s", airspy_error_name(rc));
512 qDebug() <<
"AirspyInput:applySettings: mixer gain set to " << settings.
m_mixerGain;
519 reverseAPIKeys.append(
"mixerAGC");
522 rc = (airspy_error) airspy_set_mixer_agc(
m_dev, (settings.
m_mixerAGC ? 1 : 0));
525 if (rc != AIRSPY_SUCCESS) {
526 qDebug(
"AirspyInput::applySettings: airspy_set_mixer_agc failed: %s", airspy_error_name(rc));
528 qDebug() <<
"AirspyInput:applySettings: Mixer AGC set to " << settings.
m_mixerAGC;
534 reverseAPIKeys.append(
"vgaGain");
538 rc = (airspy_error) airspy_set_vga_gain(
m_dev, settings.
m_vgaGain);
540 if (rc != AIRSPY_SUCCESS) {
541 qDebug(
"AirspyInput::applySettings: airspy_set_vga_gain failed: %s", airspy_error_name(rc));
543 qDebug() <<
"AirspyInput:applySettings: VGA gain set to " << settings.
m_vgaGain;
550 reverseAPIKeys.append(
"biasT");
554 rc = (airspy_error) airspy_set_rf_bias(
m_dev, (settings.
m_biasT ? 1 : 0));
556 if (rc != AIRSPY_SUCCESS) {
557 qDebug(
"AirspyInput::applySettings: airspy_set_rf_bias failed: %s", airspy_error_name(rc));
559 qDebug() <<
"AirspyInput:applySettings: bias tee set to " << settings.
m_biasT;
588 struct airspy_device *devinfo;
589 airspy_error rc = AIRSPY_ERROR_OTHER;
593 rc = (airspy_error) airspy_open(&devinfo);
595 if (rc == AIRSPY_SUCCESS)
600 airspy_close(devinfo);
614 QString& errorMessage)
624 QString& errorMessage)
642 QString& errorMessage)
653 const QStringList& deviceSettingsKeys,
655 QString& errorMessage)
660 if (deviceSettingsKeys.contains(
"centerFrequency")) {
663 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
666 if (deviceSettingsKeys.contains(
"devSampleRateIndex")) {
669 if (deviceSettingsKeys.contains(
"lnaGain")) {
672 if (deviceSettingsKeys.contains(
"mixerGain")) {
675 if (deviceSettingsKeys.contains(
"vgaGain")) {
678 if (deviceSettingsKeys.contains(
"lnaAGC")) {
681 if (deviceSettingsKeys.contains(
"mixerAGC")) {
684 if (deviceSettingsKeys.contains(
"log2Decim")) {
687 if (deviceSettingsKeys.contains(
"fcPos")) {
689 fcPos = fcPos < 0 ? 0 : fcPos > 2 ? 2 : fcPos;
692 if (deviceSettingsKeys.contains(
"biasT")) {
695 if (deviceSettingsKeys.contains(
"dcBlock")) {
698 if (deviceSettingsKeys.contains(
"iqCorrection")) {
701 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency")) {
704 if (deviceSettingsKeys.contains(
"transverterMode")) {
707 if (deviceSettingsKeys.contains(
"fileRecordName")) {
710 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
713 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
716 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
719 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
738 QString& errorMessage)
805 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
808 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
811 if (deviceSettingsKeys.contains(
"devSampleRateIndex") || force) {
814 if (deviceSettingsKeys.contains(
"lnaGain") || force) {
817 if (deviceSettingsKeys.contains(
"mixerGain") || force) {
820 if (deviceSettingsKeys.contains(
"vgaGain") || force) {
823 if (deviceSettingsKeys.contains(
"lnaAGC") || force) {
826 if (deviceSettingsKeys.contains(
"mixerAGC") || force) {
829 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
832 if (deviceSettingsKeys.contains(
"fcPos") || force) {
835 if (deviceSettingsKeys.contains(
"biasT") || force) {
838 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
841 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
844 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency") || force) {
847 if (deviceSettingsKeys.contains(
"transverterMode") || force) {
850 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
854 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
859 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
861 QBuffer *buffer=
new QBuffer();
862 buffer->open((QBuffer::ReadWrite));
863 buffer->write(swgDeviceSettings->
asJson().toUtf8());
869 delete swgDeviceSettings;
879 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
884 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
886 QBuffer *buffer=
new QBuffer();
887 buffer->open((QBuffer::ReadWrite));
888 buffer->write(swgDeviceSettings->
asJson().toUtf8());
897 delete swgDeviceSettings;
902 QNetworkReply::NetworkError replyError = reply->error();
906 qWarning() <<
"AirspyInput::networkManagerFinished:" 907 <<
" error(" << (int) replyError
908 <<
"): " << replyError
909 <<
": " << reply->errorString();
913 QString answer = reply->readAll();
915 qDebug(
"AirspyInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
quint32 m_devSampleRateIndex
SWGAirspyReport * getAirspyReport()
quint64 m_centerFrequency
qint32 getReverseApiPort()
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 setLOppmTenths(qint32 l_oppm_tenths)
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
void setFileName(const QString &filename)
uint getDeviceUID() const
Return the current device engine unique ID.
void setNbSourceStreams(uint32_t nbSourceStreams)
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
SWGAirspySettings * getAirspySettings()
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
static const int m_maxDevices
qint32 getDevSampleRateIndex()
void setFcPos(qint32 fc_pos)
void setAirspyReport(SWGAirspyReport *airspy_report)
void setDcBlock(qint32 dc_block)
void setOriginatorIndex(qint32 originator_index)
void setMixerAgc(qint32 mixer_agc)
SampleSinkFifo m_sampleFifo
void setAirspySettings(SWGAirspySettings *airspy_settings)
qint64 getTransverterDeltaFrequency()
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.
void setTransverterDeltaFrequency(qint64 transverter_delta_frequency)
void setLog2Decim(qint32 log2_decim)
int getDeviceSetIndex() const
void setCenterFrequency(qint64 center_frequency)
void setTransverterMode(qint32 transverter_mode)
qint32 getTransverterMode()
#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)
QString * getFileRecordName()
void setBiasT(qint32 bias_t)
void setLog2Decimation(unsigned int log2_decim)
void setIqCorrection(qint32 iq_correction)
static bool match(const Message *message)
void setReverseApiAddress(QString *reverse_api_address)
void removeAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Removes it.
qint64 getCenterFrequency()
qint64 m_transverterDeltaFrequency
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void setLnaGain(qint32 lna_gain)
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
void setDevSampleRateIndex(qint32 dev_sample_rate_index)
qint32 getReverseApiDeviceIndex()
void getDeviceEngineStateStr(QString &state)
uint16_t m_reverseAPIPort
QString * getReverseApiAddress()
void setSamplerate(uint32_t samplerate)
void setFileRecordName(QString *file_record_name)
qint32 getUseReverseApi()
QString m_reverseAPIAddress
void setVgaGain(qint32 vga_gain)
QByteArray serialize() const
bool deserialize(const QByteArray &data)
uint16_t m_reverseAPIDeviceIndex
void setUseReverseApi(qint32 use_reverse_api)
void setMixerGain(qint32 mixer_gain)
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
void setSampleRates(QList< SWGSampleRate *> *sample_rates)
uint32_t getSamplingDeviceSequence() const
void setDirection(qint32 direction)
QList< SWGSampleRate * > * getSampleRates()
void setDeviceHwType(QString *device_hw_type)
void setLnaAgc(qint32 lna_agc)
void setReverseApiPort(qint32 reverse_api_port)