22 #include <QNetworkReply> 45 m_deviceAPI(deviceAPI),
49 m_deviceDescription("HackRF"),
54 m_fileSink =
new FileRecord(QString(
"test_%1.sdriq").
arg(m_deviceAPI->getDeviceUID()));
55 m_deviceAPI->setNbSourceStreams(1);
56 m_deviceAPI->addAncillarySink(m_fileSink);
58 m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
60 m_networkManager =
new QNetworkAccessManager();
61 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
93 qCritical(
"HackRFInput::start: could not allocate SampleFifo");
102 if (buddySharedParams == 0)
104 qCritical(
"HackRFInput::openDevice: could not get shared parameters from buddy");
108 if (buddySharedParams->
m_dev == 0)
110 qCritical(
"HackRFInput::openDevice: could not get HackRF handle from buddy");
159 qDebug(
"HackRFInput::startInput: started");
169 qDebug(
"HackRFInput::closeDevice: closing device since Tx side is not open");
184 qDebug(
"HackRFInput::stop");
259 qDebug() <<
"HackRFInput::handleMessage: MsgConfigureHackRF";
265 qDebug(
"HackRFInput::handleMessage: config error");
273 qDebug() <<
"HackRFInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
295 qDebug() <<
"HackRFInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
325 qDebug(
"HackRFInput::handleMessage: MsgSynchronizeFrequency: centerFrequency: %lld Hz", centerFrequency);
355 qint64 df = ((qint64)freq_hz * LOppmTenths) / 10000000LL;
356 hackrf_error rc = (hackrf_error) hackrf_set_freq(
m_dev, static_cast<uint64_t>(freq_hz + df));
358 if (rc != HACKRF_SUCCESS) {
359 qWarning(
"HackRFInput::setDeviceCenterFrequency: could not frequency to %llu Hz", freq_hz + df);
361 qDebug(
"HackRFInput::setDeviceCenterFrequency: frequency set to %llu Hz", freq_hz + df);
369 bool forwardChange =
false;
371 QList<QString> reverseAPIKeys;
373 qDebug() <<
"HackRFInput::applySettings";
376 reverseAPIKeys.append(
"dcBlock");
379 reverseAPIKeys.append(
"iqCorrection");
390 reverseAPIKeys.append(
"devSampleRate");
391 forwardChange =
true;
397 if (rc != HACKRF_SUCCESS)
399 qCritical(
"HackRFInput::applySettings: could not set sample rate TO %llu S/s: %s", settings.
m_devSampleRate, hackrf_error_name(rc));
405 qDebug(
"HackRFInput::applySettings: sample rate set to %llu S/s", settings.
m_devSampleRate);
414 reverseAPIKeys.append(
"log2Decim");
415 forwardChange =
true;
420 qDebug() <<
"HackRFInput: set decimation to " << (1<<settings.
m_log2Decim);
425 reverseAPIKeys.append(
"centerFrequency");
429 reverseAPIKeys.append(
"LOppmTenths");
432 reverseAPIKeys.append(
"fcPos");
447 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_TXSYNC,
458 forwardChange =
true;
466 qDebug() <<
"HackRFInput: set fc pos (enum) to " << (int) settings.
m_fcPos;
472 reverseAPIKeys.append(
"lnaGain");
476 rc = (hackrf_error) hackrf_set_lna_gain(
m_dev, settings.
m_lnaGain);
478 if (rc != HACKRF_SUCCESS) {
479 qDebug(
"HackRFInput::applySettings: airspy_set_lna_gain failed: %s", hackrf_error_name(rc));
481 qDebug() <<
"HackRFInput:applySettings: LNA gain set to " << settings.
m_lnaGain;
488 reverseAPIKeys.append(
"vgaGain");
492 rc = (hackrf_error) hackrf_set_vga_gain(
m_dev, settings.
m_vgaGain);
494 if (rc != HACKRF_SUCCESS) {
495 qDebug(
"HackRFInput::applySettings: hackrf_set_vga_gain failed: %s", hackrf_error_name(rc));
497 qDebug() <<
"HackRFInput:applySettings: VGA gain set to " << settings.
m_vgaGain;
504 reverseAPIKeys.append(
"bandwidth");
508 uint32_t bw_index = hackrf_compute_baseband_filter_bw_round_down_lt(settings.
m_bandwidth + 1);
509 rc = (hackrf_error) hackrf_set_baseband_filter_bandwidth(
m_dev, bw_index);
511 if (rc != HACKRF_SUCCESS) {
512 qDebug(
"HackRFInput::applySettings: hackrf_set_baseband_filter_bandwidth failed: %s", hackrf_error_name(rc));
514 qDebug() <<
"HackRFInput:applySettings: Baseband BW filter set to " << settings.
m_bandwidth <<
" Hz";
521 reverseAPIKeys.append(
"biasT");
525 rc = (hackrf_error) hackrf_set_antenna_enable(
m_dev, (settings.
m_biasT ? 1 : 0));
527 if (rc != HACKRF_SUCCESS) {
528 qDebug(
"HackRFInput::applySettings: hackrf_set_antenna_enable failed: %s", hackrf_error_name(rc));
530 qDebug() <<
"HackRFInput:applySettings: bias tee set to " << settings.
m_biasT;
537 reverseAPIKeys.append(
"lnaExt");
541 rc = (hackrf_error) hackrf_set_amp_enable(
m_dev, (settings.
m_lnaExt ? 1 : 0));
543 if (rc != HACKRF_SUCCESS) {
544 qDebug(
"HackRFInput::applySettings: hackrf_set_amp_enable failed: %s", hackrf_error_name(rc));
546 qDebug() <<
"HackRFInput:applySettings: extra LNA set to " << settings.
m_lnaExt;
570 qDebug() <<
"HackRFInput::applySettings: " 588 QString& errorMessage)
599 const QStringList& deviceSettingsKeys,
601 QString& errorMessage)
606 if (deviceSettingsKeys.contains(
"centerFrequency")) {
609 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
612 if (deviceSettingsKeys.contains(
"bandwidth")) {
615 if (deviceSettingsKeys.contains(
"lnaGain")) {
618 if (deviceSettingsKeys.contains(
"vgaGain")) {
621 if (deviceSettingsKeys.contains(
"log2Decim")) {
624 if (deviceSettingsKeys.contains(
"fcPos"))
627 fcPos = fcPos < 0 ? 0 : fcPos > 2 ? 2 : fcPos;
630 if (deviceSettingsKeys.contains(
"devSampleRate")) {
633 if (deviceSettingsKeys.contains(
"biasT")) {
636 if (deviceSettingsKeys.contains(
"lnaExt")) {
639 if (deviceSettingsKeys.contains(
"dcBlock")) {
642 if (deviceSettingsKeys.contains(
"iqCorrection")) {
645 if (deviceSettingsKeys.contains(
"fileRecordName")) {
648 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
651 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
654 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
657 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
709 QString& errorMessage)
719 QString& errorMessage)
746 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
749 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
752 if (deviceSettingsKeys.contains(
"bandwidth") || force) {
755 if (deviceSettingsKeys.contains(
"lnaGain") || force) {
758 if (deviceSettingsKeys.contains(
"vgaGain") || force) {
761 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
764 if (deviceSettingsKeys.contains(
"fcPos") || force) {
767 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
770 if (deviceSettingsKeys.contains(
"biasT") || force) {
773 if (deviceSettingsKeys.contains(
"lnaExt") || force) {
776 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
779 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
782 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
786 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
791 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
793 QBuffer *buffer=
new QBuffer();
794 buffer->open((QBuffer::ReadWrite));
795 buffer->write(swgDeviceSettings->
asJson().toUtf8());
801 delete swgDeviceSettings;
811 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
816 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
818 QBuffer *buffer=
new QBuffer();
819 buffer->open((QBuffer::ReadWrite));
820 buffer->write(swgDeviceSettings->
asJson().toUtf8());
829 delete swgDeviceSettings;
834 QNetworkReply::NetworkError replyError = reply->error();
838 qWarning() <<
"HackRFInput::networkManagerFinished:" 839 <<
" error(" << (int) replyError
840 <<
"): " << replyError
841 <<
": " << reply->errorString();
845 QString answer = reply->readAll();
847 qDebug(
"HackRFInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
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.
void setFileName(const QString &filename)
uint getDeviceUID() const
Return the current device engine unique ID.
const std::vector< DeviceAPI * > & getSinkBuddies() const
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
void setOriginatorIndex(qint32 originator_index)
static hackrf_device * open_hackrf(int sequence)
SampleSinkFifo m_sampleFifo
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.
int getDeviceSetIndex() const
void * getBuddySharedPtr() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
void genUniqueFileName(uint deviceUID, int istream=-1)
void setBuddySharedPtr(void *ptr)
MessageQueue * getSamplingDeviceInputMessageQueue()
Sampling device (ex: single Rx) input message queue.
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.
static MsgSynchronizeFrequency * create(uint64_t frequency)
void getDeviceEngineStateStr(QString &state)
const QString & getSamplingDeviceSerial() const
void setHackRfInputSettings(SWGHackRFInputSettings *hack_rf_input_settings)
SWGHackRFInputSettings * getHackRfInputSettings()
uint64_t getFrequency() const
struct hackrf_device * m_dev
device handle if the party has ownership else 0
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
static qint64 calculateCenterFrequency(quint64 deviceCenterFrequency, qint64 transverterDeltaFrequency, int log2Decim, fcPos_t fcPos, quint32 devSampleRate, FrequencyShiftScheme frequencyShiftScheme, bool transverterMode=false)
void setDirection(qint32 direction)
void setDeviceHwType(QString *device_hw_type)