22 #include <QNetworkReply> 51 m_deviceAPI(deviceAPI),
55 m_deviceDescription(
"AirspyHF"),
96 qCritical(
"AirspyHFInput::openDevice: could not allocate SampleFifo");
114 rc = (airspyhf_error) airspyhf_get_samplerates(
m_dev, &nbSampleRates, 0);
116 if (rc == AIRSPYHF_SUCCESS)
118 qDebug(
"AirspyHFInput::openDevice: %d sample rates for Airspy HF", nbSampleRates);
122 qCritical(
"AirspyHFInput::openDevice: could not obtain the number of Airspy HF sample rates");
127 sampleRates =
new uint32_t[nbSampleRates];
129 rc = (airspyhf_error) airspyhf_get_samplerates(
m_dev, sampleRates, nbSampleRates);
131 if (rc == AIRSPYHF_SUCCESS)
133 qDebug(
"AirspyHFInput::openDevice: obtained Airspy HF sample rates");
137 qCritical(
"AirspyHFInput::openDevice: could not obtain Airspy HF sample rates");
144 for (
unsigned int i = 0;
i < nbSampleRates;
i++)
147 qDebug(
"AirspyHFInput::openDevice: sampleRates[%d] = %u Hz", i, sampleRates[i]);
150 delete[] sampleRates;
162 QMutexLocker mutexLocker(&
m_mutex);
177 if (sampleRateIndex >= 0) {
184 mutexLocker.unlock();
188 qDebug(
"AirspyHFInput::startInput: started");
198 airspyhf_stop(
m_dev);
199 airspyhf_close(
m_dev);
208 qDebug(
"AirspyHFInput::stop");
209 QMutexLocker mutexLocker(&
m_mutex);
261 if (sampleRateIndex >= 0)
297 qDebug() <<
"MsgConfigureAirspyHF::handleMessage: MsgConfigureAirspyHF";
303 qDebug(
"MsgConfigureAirspyHF::handleMessage: AirspyHF config error");
311 qDebug() <<
"AirspyHFInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
334 qDebug() <<
"AirspyHFInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
372 airspyhf_error rc = (airspyhf_error) airspyhf_set_freq(
m_dev, static_cast<uint32_t>(freq_hz));
374 if (rc == AIRSPYHF_SUCCESS) {
375 qDebug(
"AirspyHFInput::setDeviceCenterFrequency: frequency set to %llu Hz", freq_hz);
377 qWarning(
"AirspyHFInput::setDeviceCenterFrequency: could not frequency to %llu Hz", freq_hz);
383 qDebug() <<
"AirspyHFInput::applySettings: " 392 <<
" m_useDSP: " << settings.
m_useDSP 393 <<
" m_useAGC: " << settings.
m_useAGC 395 <<
" m_useLNA: " << settings.
m_useLNA 404 QMutexLocker mutexLocker(&
m_mutex);
406 bool forwardChange =
false;
408 QList<QString> reverseAPIKeys;
413 reverseAPIKeys.append(
"dcBlock");
416 reverseAPIKeys.append(
"iqCorrection");
426 reverseAPIKeys.append(
"bandIndex");
431 reverseAPIKeys.append(
"devSampleRateIndex");
432 forwardChange =
true;
438 if ((
m_dev != 0) && (sampleRateIndex >= 0))
440 rc = (airspyhf_error) airspyhf_set_samplerate(
m_dev, sampleRateIndex);
442 if (rc != AIRSPYHF_SUCCESS)
444 qCritical(
"AirspyHFInput::applySettings: could not set sample rate index %u (%d S/s)", sampleRateIndex,
m_sampleRates[sampleRateIndex]);
448 qDebug(
"AirspyHFInput::applySettings: sample rate set to index: %u (%d S/s)", sampleRateIndex,
m_sampleRates[sampleRateIndex]);
456 reverseAPIKeys.append(
"log2Decim");
457 forwardChange =
true;
462 qDebug() <<
"AirspyInput: set decimation to " << (1<<settings.
m_log2Decim);
468 reverseAPIKeys.append(
"LOppmTenths");
474 if (rc != AIRSPYHF_SUCCESS)
476 qCritical(
"AirspyHFInput::applySettings: could not set LO ppm correction to %f", settings.
m_LOppmTenths / 10.0f);
480 qDebug(
"AirspyHFInput::applySettings: LO ppm correction set to %f", settings.
m_LOppmTenths / 10.0f);
486 reverseAPIKeys.append(
"centerFrequency");
489 reverseAPIKeys.append(
"transverterMode");
492 reverseAPIKeys.append(
"transverterDeltaFrequency");
501 deviceCenterFrequency = deviceCenterFrequency < 0 ? 0 : deviceCenterFrequency;
502 qint64 f_img = deviceCenterFrequency;
504 if ((
m_dev != 0) && (sampleRateIndex >= 0))
509 qDebug() <<
"AirspyHFInput::applySettings: center freq: " << settings.
m_centerFrequency <<
" Hz" 510 <<
" device center freq: " << deviceCenterFrequency <<
" Hz" 511 <<
" device sample rate: " << devSampleRate <<
"Hz" 513 <<
" img: " << f_img <<
"Hz";
516 forwardChange =
true;
521 reverseAPIKeys.append(
"useAGC");
525 rc = (airspyhf_error) airspyhf_set_hf_agc(
m_dev, settings.
m_useAGC ? 1 : 0);
527 if (rc != AIRSPYHF_SUCCESS) {
528 qCritical(
"AirspyHFInput::applySettings: could not set AGC to %d", settings.
m_useAGC ? 1 : 0);
530 qDebug(
"AirspyHFInput::applySettings: set AGC to %d", settings.
m_useAGC ? 1 : 0);
537 reverseAPIKeys.append(
"agcHigh");
541 rc = (airspyhf_error) airspyhf_set_hf_agc_threshold(
m_dev, settings.
m_agcHigh ? 1 : 0);
543 if (rc != AIRSPYHF_SUCCESS) {
544 qCritical(
"AirspyHFInput::applySettings: could not set AGC to %s", settings.
m_agcHigh ?
"high" :
"low");
546 qDebug(
"AirspyHFInput::applySettings: set AGC to %s", settings.
m_agcHigh ?
"high" :
"low");
553 reverseAPIKeys.append(
"useDSP");
557 rc = (airspyhf_error) airspyhf_set_lib_dsp(
m_dev, settings.
m_useDSP ? 1 : 0);
559 if (rc != AIRSPYHF_SUCCESS) {
560 qCritical(
"AirspyHFInput::applySettings: could not set DSP to %d", settings.
m_useDSP ? 1 : 0);
562 qDebug(
"AirspyHFInput::applySettings: set DSP to %d", settings.
m_useDSP ? 1 : 0);
569 reverseAPIKeys.append(
"useLNA");
573 rc = (airspyhf_error) airspyhf_set_hf_lna(
m_dev, settings.
m_useLNA ? 1 : 0);
575 if (rc != AIRSPYHF_SUCCESS) {
576 qCritical(
"AirspyHFInput::applySettings: could not set LNA to %d", settings.
m_useLNA ? 1 : 0);
578 qDebug(
"AirspyHFInput::applySettings: set LNA to %d", settings.
m_useLNA ? 1 : 0);
585 reverseAPIKeys.append(
"attenuatorSteps");
591 if (rc != AIRSPYHF_SUCCESS) {
592 qCritical(
"AirspyHFInput::applySettings: could not set attenuator to %d dB", settings.
m_attenuatorSteps * 6);
594 qDebug(
"AirspyHFInput::applySettings: set attenuator to %d dB", settings.
m_attenuatorSteps * 6);
599 if (forwardChange && (sampleRateIndex >= 0))
622 airspyhf_device_t *devinfo;
626 uint64_t serial = serialStr.toULongLong(&ok, 16);
630 qCritical(
"AirspyHFInput::open_airspyhf_from_serial: invalid serial %s", qPrintable(serialStr));
635 rc = (airspyhf_error) airspyhf_open_sn(&devinfo, serial);
637 if (rc == AIRSPYHF_SUCCESS) {
647 QString& errorMessage)
658 const QStringList& deviceSettingsKeys,
660 QString& errorMessage)
665 if (deviceSettingsKeys.contains(
"centerFrequency")) {
668 if (deviceSettingsKeys.contains(
"devSampleRateIndex")) {
671 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
674 if (deviceSettingsKeys.contains(
"log2Decim")) {
677 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency")) {
680 if (deviceSettingsKeys.contains(
"transverterMode")) {
683 if (deviceSettingsKeys.contains(
"bandIndex")) {
686 if (deviceSettingsKeys.contains(
"fileRecordName")) {
689 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
692 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
695 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
698 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
701 if (deviceSettingsKeys.contains(
"useAGC")) {
704 if (deviceSettingsKeys.contains(
"agcHigh")) {
707 if (deviceSettingsKeys.contains(
"useDSP")) {
710 if (deviceSettingsKeys.contains(
"useLNA")) {
713 if (deviceSettingsKeys.contains(
"attenuatorSteps")) {
716 if (deviceSettingsKeys.contains(
"dcBlock")) {
719 if (deviceSettingsKeys.contains(
"iqCorrection")) {
784 QString& errorMessage)
795 QString& errorMessage)
805 QString& errorMessage)
832 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
835 if (deviceSettingsKeys.contains(
"devSampleRateIndex") || force) {
838 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
841 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
844 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency") || force) {
847 if (deviceSettingsKeys.contains(
"transverterMode") || force) {
850 if (deviceSettingsKeys.contains(
"bandIndex") || force) {
853 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
856 if (deviceSettingsKeys.contains(
"useAGC")) {
859 if (deviceSettingsKeys.contains(
"agcHigh")) {
862 if (deviceSettingsKeys.contains(
"useDSP")) {
865 if (deviceSettingsKeys.contains(
"useLNA")) {
868 if (deviceSettingsKeys.contains(
"attenuatorSteps")) {
871 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
874 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
878 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
883 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
885 QBuffer *buffer=
new QBuffer();
886 buffer->open((QBuffer::ReadWrite));
887 buffer->write(swgDeviceSettings->
asJson().toUtf8());
893 delete swgDeviceSettings;
903 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
908 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
910 QBuffer *buffer=
new QBuffer();
911 buffer->open((QBuffer::ReadWrite));
912 buffer->write(swgDeviceSettings->
asJson().toUtf8());
921 delete swgDeviceSettings;
926 QNetworkReply::NetworkError replyError = reply->error();
930 qWarning() <<
"AirspyHFInput::networkManagerFinished:" 931 <<
" error(" << (int) replyError
932 <<
"): " << replyError
933 <<
": " << reply->errorString();
937 QString answer = reply->readAll();
939 qDebug(
"AirspyHFInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool deserialize(const QByteArray &data)
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
quint32 m_attenuatorSteps
void push(Message *message, bool emitSignal=true)
Push message onto queue.
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)
void setLog2Decimation(unsigned int log2_decim)
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
void setUseReverseApi(qint32 use_reverse_api)
uint16_t m_reverseAPIDeviceIndex
uint16_t m_reverseAPIPort
void setReverseApiAddress(QString *reverse_api_address)
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
void setTransverterDeltaFrequency(qint64 transverter_delta_frequency)
QString * getReverseApiAddress()
qint32 getAttenuatorSteps()
void setSamplerate(uint32_t samplerate)
void setOriginatorIndex(qint32 originator_index)
qint32 getTransverterMode()
SampleSinkFifo m_sampleFifo
Fixed< IntType, IntBits > arg(const std::complex< Fixed< IntType, IntBits > > &val)
void setDcBlock(qint32 dc_block)
virtual bool handleMessage(const Message &message)
Processing of a message. Returns true if message has actually been processed.
void setUseAgc(qint32 use_agc)
qint32 getReverseApiDeviceIndex()
void setDevSampleRateIndex(qint32 dev_sample_rate_index)
int getDeviceSetIndex() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
QList< SWGSampleRate * > * getSampleRates()
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 setLog2Decim(qint32 log2_decim)
qint64 getCenterFrequency()
qint64 m_transverterDeltaFrequency
void setBandIndex(qint32 band_index)
QString * getFileRecordName()
static bool match(const Message *message)
QString m_reverseAPIAddress
void setLOppmTenths(qint32 l_oppm_tenths)
void removeAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Removes it.
quint32 m_devSampleRateIndex
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void setUseDsp(qint32 use_dsp)
void setIqCorrection(qint32 iq_correction)
void getDeviceEngineStateStr(QString &state)
SWGAirspyHFSettings * getAirspyHfSettings()
const QString & getSamplingDeviceSerial() const
quint64 m_centerFrequency
qint32 getDevSampleRateIndex()
void setSampleRates(QList< SWGSampleRate *> *sample_rates)
void setReverseApiPort(qint32 reverse_api_port)
void setAirspyHfReport(SWGAirspyHFReport *airspy_hf_report)
void setCenterFrequency(qint64 center_frequency)
void setFileRecordName(QString *file_record_name)
QByteArray serialize() const
void setAgcHigh(qint32 agc_high)
qint32 getUseReverseApi()
qint32 getReverseApiPort()
void setUseLna(qint32 use_lna)
void setAirspyHfSettings(SWGAirspyHFSettings *airspy_hf_settings)
void setTransverterMode(qint32 transverter_mode)
qint64 getTransverterDeltaFrequency()
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
void setDirection(qint32 direction)
void setAttenuatorSteps(qint32 attenuator_steps)
void setDeviceHwType(QString *device_hw_type)
SWGAirspyHFReport * getAirspyHfReport()
unsigned __int64 uint64_t