22 #include <QNetworkReply> 41 m_deviceAPI(deviceAPI),
49 m_deviceAPI->setNbSinkStreams(1);
50 m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
51 m_networkManager =
new QNetworkAccessManager();
52 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
87 if (buddySharedParams == 0)
89 qCritical(
"HackRFOutput::openDevice: could not get shared parameters from buddy");
95 qCritical(
"HackRFOutput::openDevice: could not get HackRF handle from buddy");
142 qDebug(
"HackRFOutput::start: started");
152 qDebug(
"HackRFOutput::closeDevice: closing device since Rx side is not open");
167 qDebug(
"HackRFOutput::stop");
243 qDebug() <<
"HackRFOutput::handleMessage: MsgConfigureHackRF";
249 qDebug(
"HackRFOutput::handleMessage: MsgConfigureHackRF: config error");
257 qDebug() <<
"HackRFOutput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
286 qDebug(
"HackRFOutput::handleMessage: MsgSynchronizeFrequency: centerFrequency: %lld Hz", centerFrequency);
315 qint64 df = ((qint64)freq_hz * LOppmTenths) / 10000000LL;
316 hackrf_error rc = (hackrf_error) hackrf_set_freq(
m_dev, static_cast<uint64_t>(freq_hz + df));
318 if (rc != HACKRF_SUCCESS) {
319 qWarning(
"HackRFOutput::setDeviceCenterFrequency: could not frequency to %llu Hz", freq_hz + df);
321 qDebug(
"HackRFOutput::setDeviceCenterFrequency: frequency set to %llu Hz", freq_hz + df);
329 bool forwardChange =
false;
330 bool suspendThread =
false;
331 bool threadWasRunning =
false;
333 QList<QString> reverseAPIKeys;
335 qDebug() <<
"HackRFOutput::applySettings" 341 <<
" m_fcPos: " << settings.
m_fcPos 342 <<
" m_biasT: " << settings.
m_biasT 343 <<
" m_lnaExt: " << settings.
m_lnaExt 349 <<
" force: " << force;
352 reverseAPIKeys.append(
"devSampleRate");
358 suspendThread =
true;
368 threadWasRunning =
true;
375 forwardChange =
true;
388 if (rc != HACKRF_SUCCESS)
390 qCritical(
"HackRFOutput::applySettings: could not set sample rate to %llu S/s: %s",
392 hackrf_error_name(rc));
396 qDebug(
"HackRFOutput::applySettings: sample rate set to %llu S/s",
404 reverseAPIKeys.append(
"log2Interp");
409 qDebug() <<
"HackRFOutput: set interpolation to " << (1<<settings.
m_log2Interp);
414 reverseAPIKeys.append(
"centerFrequency");
417 reverseAPIKeys.append(
"LOppmTenths");
420 reverseAPIKeys.append(
"fcPos");
444 forwardChange =
true;
456 reverseAPIKeys.append(
"vgaGain");
460 rc = (hackrf_error) hackrf_set_txvga_gain(
m_dev, settings.
m_vgaGain);
462 if (rc != HACKRF_SUCCESS) {
463 qDebug(
"HackRFOutput::applySettings: hackrf_set_txvga_gain failed: %s", hackrf_error_name(rc));
465 qDebug() <<
"HackRFOutput:applySettings: TxVGA gain set to " << settings.
m_vgaGain;
472 reverseAPIKeys.append(
"bandwidth");
476 uint32_t bw_index = hackrf_compute_baseband_filter_bw_round_down_lt(settings.
m_bandwidth + 1);
477 rc = (hackrf_error) hackrf_set_baseband_filter_bandwidth(
m_dev, bw_index);
479 if (rc != HACKRF_SUCCESS) {
480 qDebug(
"HackRFInput::applySettings: hackrf_set_baseband_filter_bandwidth failed: %s", hackrf_error_name(rc));
482 qDebug() <<
"HackRFInput:applySettings: Baseband BW filter set to " << settings.
m_bandwidth <<
" Hz";
489 reverseAPIKeys.append(
"biasT");
493 rc = (hackrf_error) hackrf_set_antenna_enable(
m_dev, (settings.
m_biasT ? 1 : 0));
495 if (rc != HACKRF_SUCCESS) {
496 qDebug(
"HackRFInput::applySettings: hackrf_set_antenna_enable failed: %s", hackrf_error_name(rc));
498 qDebug() <<
"HackRFInput:applySettings: bias tee set to " << settings.
m_biasT;
505 reverseAPIKeys.append(
"lnaExt");
509 rc = (hackrf_error) hackrf_set_amp_enable(
m_dev, (settings.
m_lnaExt ? 1 : 0));
511 if (rc != HACKRF_SUCCESS) {
512 qDebug(
"HackRFInput::applySettings: hackrf_set_amp_enable failed: %s", hackrf_error_name(rc));
514 qDebug() <<
"HackRFInput:applySettings: extra LNA set to " << settings.
m_lnaExt;
519 if (threadWasRunning)
547 QString& errorMessage)
558 const QStringList& deviceSettingsKeys,
560 QString& errorMessage)
565 if (deviceSettingsKeys.contains(
"centerFrequency")) {
568 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
571 if (deviceSettingsKeys.contains(
"bandwidth")) {
574 if (deviceSettingsKeys.contains(
"vgaGain")) {
577 if (deviceSettingsKeys.contains(
"log2Interp")) {
580 if (deviceSettingsKeys.contains(
"fcPos"))
583 fcPos = fcPos < 0 ? 0 : fcPos > 2 ? 2 : fcPos;
586 if (deviceSettingsKeys.contains(
"devSampleRate")) {
589 if (deviceSettingsKeys.contains(
"biasT")) {
592 if (deviceSettingsKeys.contains(
"lnaExt")) {
595 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
598 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
601 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
604 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
647 QString& errorMessage)
657 QString& errorMessage)
684 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
687 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
690 if (deviceSettingsKeys.contains(
"bandwidth") || force) {
693 if (deviceSettingsKeys.contains(
"vgaGain") || force) {
696 if (deviceSettingsKeys.contains(
"log2Interp") || force) {
699 if (deviceSettingsKeys.contains(
"fcPos") || force) {
702 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
705 if (deviceSettingsKeys.contains(
"biasT") || force) {
708 if (deviceSettingsKeys.contains(
"lnaExt") || force) {
712 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
717 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
719 QBuffer *buffer=
new QBuffer();
720 buffer->open((QBuffer::ReadWrite));
721 buffer->write(swgDeviceSettings->
asJson().toUtf8());
727 delete swgDeviceSettings;
737 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
742 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
744 QBuffer *buffer=
new QBuffer();
745 buffer->open((QBuffer::ReadWrite));
746 buffer->write(swgDeviceSettings->
asJson().toUtf8());
755 delete swgDeviceSettings;
760 QNetworkReply::NetworkError replyError = reply->error();
764 qWarning() <<
"HackRFOutput::networkManagerFinished:" 765 <<
" error(" << (int) replyError
766 <<
"): " << replyError
767 <<
": " << reply->errorString();
771 QString answer = reply->readAll();
773 qDebug(
"HackRFOutput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
struct hackrf_device * m_dev
virtual int getSampleRate() const
Sample rate exposed by the sink.
QNetworkRequest m_networkRequest
uint16_t m_reverseAPIDeviceIndex
virtual const QString & getDeviceDescription() const
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
void setUseReverseApi(qint32 use_reverse_api)
static const float m_sampleFifoLengthInSeconds
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const HackRFOutputSettings &settings, bool force)
virtual QString asJson() override
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const HackRFOutputSettings &settings)
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
virtual bool deserialize(const QByteArray &data)
void setFcPos(qint32 fc_pos)
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
void setReverseApiPort(qint32 reverse_api_port)
void setOriginatorIndex(qint32 originator_index)
static hackrf_device * open_hackrf(int sequence)
virtual QByteArray serialize() const
void setDevSampleRate(qint32 dev_sample_rate)
virtual quint64 getCenterFrequency() const
Center frequency exposed by the sink.
MessageQueue m_inputMessageQueue
Input queue to the sink.
void setLnaExt(qint32 lna_ext)
QString * getReverseApiAddress()
HackRFOutputSettings m_settings
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
virtual bool handleMessage(const Message &message)
int getDeviceSetIndex() const
static const int m_sampleFifoMinSize
void * getBuddySharedPtr() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
void setHackRfOutputSettings(SWGHackRFOutputSettings *hack_rf_output_settings)
qint32 getReverseApiDeviceIndex()
qint32 getUseReverseApi()
QString m_deviceDescription
void setBuddySharedPtr(void *ptr)
MessageQueue * getSamplingDeviceInputMessageQueue()
Sampling device (ex: single Rx) input message queue.
virtual void setCenterFrequency(qint64 centerFrequency)
static bool match(const Message *message)
qint32 getDevSampleRate()
qint64 getCenterFrequency()
bool deserialize(const QByteArray &data)
void setVgaGain(qint32 vga_gain)
static MsgSynchronizeFrequency * create(uint64_t frequency)
static qint64 calculateCenterFrequency(quint64 deviceCenterFrequency, qint64 transverterDeltaFrequency, int log2Interp, fcPos_t fcPos, quint32 devSampleRate, bool transverterMode=false)
void setLOppmTenths(qint32 l_oppm_tenths)
QString m_reverseAPIAddress
void setCenterFrequency(qint64 center_frequency)
qint32 getReverseApiPort()
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
void setLog2Interpolation(unsigned int log2_interp)
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
void getDeviceEngineStateStr(QString &state)
void resize(uint32_t size)
const QString & getSamplingDeviceSerial() const
quint64 m_centerFrequency
bool getStartStop() const
void webapiReverseSendStartStop(bool start)
SampleSourceFifo m_sampleSourceFifo
const std::vector< DeviceAPI * > & getSourceBuddies() const
HackRFOutputThread * m_hackRFThread
SWGHackRFOutputSettings * getHackRfOutputSettings()
uint64_t getFrequency() const
void setReverseApiAddress(QString *reverse_api_address)
uint16_t m_reverseAPIPort
void setBiasT(qint32 bias_t)
void setDeviceCenterFrequency(quint64 freq_hz, qint32 LOppmTenths)
static qint64 calculateDeviceCenterFrequency(quint64 centerFrequency, qint64 transverterDeltaFrequency, int log2Interp, fcPos_t fcPos, quint32 devSampleRate, bool transverterMode=false)
struct hackrf_device * m_dev
device handle if the party has ownership else 0
QNetworkAccessManager * m_networkManager
DeviceHackRFParams m_sharedParams
void setBandwidth(qint32 bandwidth)
static MsgStartStop * create(bool startStop)
void setDirection(qint32 direction)
QByteArray serialize() const
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
bool applySettings(const HackRFOutputSettings &settings, bool force)
T max(const T &x, const T &y)
void setDeviceHwType(QString *device_hw_type)
void setLog2Interp(qint32 log2_interp)
void networkManagerFinished(QNetworkReply *reply)