22 #include <QNetworkReply> 42 m_deviceAPI(deviceAPI),
46 m_deviceDescription("BladeRFOutput"),
51 m_deviceAPI->setNbSinkStreams(1);
52 m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
53 m_networkManager =
new QNetworkAccessManager();
54 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
91 if (buddySharedParams == 0)
93 qCritical(
"BladerfOutput::start: could not get shared parameters from buddy");
97 if (buddySharedParams->
m_dev == 0)
99 qCritical(
"BladerfOutput::start: could not get BladeRF handle from buddy");
118 if ((res = bladerf_sync_config(
m_dev, BLADERF_TX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
120 qCritical(
"BladerfOutput::start: bladerf_sync_config with return code %d", res);
124 if ((res = bladerf_enable_module(
m_dev, BLADERF_MODULE_TX,
true)) < 0)
126 qCritical(
"BladerfOutput::start: bladerf_enable_module with return code %d", res);
157 qDebug(
"BladerfOutput::start: started");
171 if ((res = bladerf_enable_module(
m_dev, BLADERF_MODULE_TX,
false)) < 0)
173 qCritical(
"BladerfOutput::closeDevice: bladerf_enable_module with return code %d", res);
178 qDebug(
"BladerfOutput::closeDevice: closing device since Rx side is not open");
182 bladerf_close(
m_dev);
266 qDebug() <<
"BladerfOutput::handleMessage: MsgConfigureBladerf";
270 qDebug(
"BladeRF config error");
278 qDebug() <<
"BladerfOutput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
306 bool forwardChange =
false;
307 bool suspendOwnThread =
false;
308 bool threadWasRunning =
false;
309 QList<QString> reverseAPIKeys;
312 qDebug() <<
"BladerfOutput::applySettings: m_dev: " <<
m_dev;
315 reverseAPIKeys.append(
"centerFrequency");
318 reverseAPIKeys.append(
"devSampleRate");
321 reverseAPIKeys.append(
"log2Interp");
327 suspendOwnThread =
true;
330 if (suspendOwnThread)
337 threadWasRunning =
true;
362 forwardChange =
true;
366 unsigned int actualSamplerate;
368 if (bladerf_set_sample_rate(
m_dev, BLADERF_MODULE_TX, settings.
m_devSampleRate, &actualSamplerate) < 0) {
369 qCritical(
"BladerfOutput::applySettings: could not set sample rate: %d", settings.
m_devSampleRate);
371 qDebug() <<
"BladerfOutput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_TX) actual sample rate is " << actualSamplerate;
378 forwardChange =
true;
383 qDebug() <<
"BladerfOutput::applySettings: set interpolation to " << (1<<settings.
m_log2Interp);
389 reverseAPIKeys.append(
"vga1");
393 if (bladerf_set_txvga1(
m_dev, settings.
m_vga1) != 0) {
394 qDebug(
"BladerfOutput::applySettings: bladerf_set_txvga1() failed");
396 qDebug() <<
"BladerfOutput::applySettings: VGA1 gain set to " << settings.
m_vga1;
403 reverseAPIKeys.append(
"vga2");
407 if (bladerf_set_txvga2(
m_dev, settings.
m_vga2) != 0) {
408 qDebug(
"BladerfOutput::applySettings:bladerf_set_rxvga2() failed");
410 qDebug() <<
"BladerfOutput::applySettings: VGA2 gain set to " << settings.
m_vga2;
417 reverseAPIKeys.append(
"xb200");
428 changeSettings =
false;
430 changeSettings =
true;
435 changeSettings =
true;
442 if (bladerf_expansion_attach(
m_dev, BLADERF_XB_200) != 0) {
443 qDebug(
"BladerfOutput::applySettings: bladerf_expansion_attach(xb200) failed");
445 qDebug() <<
"BladerfOutput::applySettings: Attach XB200";
450 if (bladerf_expansion_attach(
m_dev, BLADERF_XB_NONE) != 0) {
451 qDebug(
"BladerfOutput::applySettings: bladerf_expansion_attach(none) failed");
453 qDebug() <<
"BladerfOutput::applySettings: Detach XB200";
464 reverseAPIKeys.append(
"xb200Path");
468 if (bladerf_xb200_set_path(
m_dev, BLADERF_MODULE_TX, settings.
m_xb200Path) != 0) {
469 qDebug(
"BladerfOutput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_TX) failed");
471 qDebug() <<
"BladerfOutput::applySettings: set xb200 path to " << settings.
m_xb200Path;
478 reverseAPIKeys.append(
"xb200Filter");
482 if (bladerf_xb200_set_filterbank(
m_dev, BLADERF_MODULE_TX, settings.
m_xb200Filter) != 0) {
483 qDebug(
"BladerfOutput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_TX) failed");
485 qDebug() <<
"BladerfOutput::applySettings: set xb200 filter to " << settings.
m_xb200Filter;
492 reverseAPIKeys.append(
"bandwidth");
496 unsigned int actualBandwidth;
498 if (bladerf_set_bandwidth(
m_dev, BLADERF_MODULE_TX, settings.
m_bandwidth, &actualBandwidth) < 0) {
499 qCritical(
"BladerfOutput::applySettings: could not set bandwidth: %d", settings.
m_bandwidth);
501 qDebug() <<
"BladerfOutput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_TX) actual bandwidth is " << actualBandwidth;
508 forwardChange =
true;
515 qDebug(
"BladerfOutput::applySettings: bladerf_set_frequency(%lld) failed", settings.
m_centerFrequency);
519 if (threadWasRunning)
552 QString& errorMessage)
587 const QStringList& deviceSettingsKeys,
589 QString& errorMessage)
594 if (deviceSettingsKeys.contains(
"centerFrequency")) {
597 if (deviceSettingsKeys.contains(
"devSampleRate")) {
600 if (deviceSettingsKeys.contains(
"vga1")) {
603 if (deviceSettingsKeys.contains(
"vga2")) {
606 if (deviceSettingsKeys.contains(
"bandwidth")) {
609 if (deviceSettingsKeys.contains(
"log2Interp")) {
612 if (deviceSettingsKeys.contains(
"xb200")) {
615 if (deviceSettingsKeys.contains(
"xb200Path")) {
618 if (deviceSettingsKeys.contains(
"xb200Filter")) {
621 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
624 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
627 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
630 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
649 QString& errorMessage)
659 QString& errorMessage)
686 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
689 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
692 if (deviceSettingsKeys.contains(
"vga1") || force) {
695 if (deviceSettingsKeys.contains(
"vga2") || force) {
698 if (deviceSettingsKeys.contains(
"bandwidth") || force) {
701 if (deviceSettingsKeys.contains(
"log2Interp") || force) {
704 if (deviceSettingsKeys.contains(
"xb200") || force) {
707 if (deviceSettingsKeys.contains(
"xb200Path") || force) {
710 if (deviceSettingsKeys.contains(
"xb200Filter") || force) {
714 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
719 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
721 QBuffer *buffer=
new QBuffer();
722 buffer->open((QBuffer::ReadWrite));
723 buffer->write(swgDeviceSettings->
asJson().toUtf8());
729 delete swgDeviceSettings;
739 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
744 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
746 QBuffer *buffer=
new QBuffer();
747 buffer->open((QBuffer::ReadWrite));
748 buffer->write(swgDeviceSettings->
asJson().toUtf8());
757 delete swgDeviceSettings;
762 QNetworkReply::NetworkError replyError = reply->error();
766 qWarning() <<
"Bladerf1Output::networkManagerFinished:" 767 <<
" error(" << (int) replyError
768 <<
"): " << replyError
769 <<
": " << reply->errorString();
773 QString answer = reply->readAll();
775 qDebug(
"Bladerf1Output::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
virtual QByteArray serialize() const
static bool open_bladerf(struct bladerf **dev, const char *serial)
bool m_xb200Attached
true if XB200 is attached and owned by the party
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
virtual bool handleMessage(const Message &message)
void setBladeRf1OutputSettings(SWGBladeRF1OutputSettings *blade_rf1_output_settings)
virtual void init()
initializations to be done when all collaborating objects are created and possibly connected ...
#define BLADERFOUTPUT_BLOCKSIZE
bool getStartStop() const
void push(Message *message, bool emitSignal=true)
Push message onto queue.
bool deserialize(const QByteArray &data)
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
virtual int webapiSettingsGet(SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
QNetworkRequest m_networkRequest
virtual const QString & getDeviceDescription() const
virtual void setCenterFrequency(qint64 centerFrequency)
SWGBladeRF1OutputSettings * getBladeRf1OutputSettings()
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
void webapiFormatDeviceSettings(SWGSDRangel::SWGDeviceSettings &response, const BladeRF1OutputSettings &settings)
bladerf_xb200_path m_xb200Path
QString m_deviceDescription
static const int m_sampleFifoMinSize32
qint32 getReverseApiDeviceIndex()
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
void setOriginatorIndex(qint32 originator_index)
qint32 getUseReverseApi()
static const float m_sampleFifoLengthInSeconds
void setReverseApiPort(qint32 reverse_api_port)
MessageQueue m_inputMessageQueue
Input queue to the sink.
void setReverseApiAddress(QString *reverse_api_address)
virtual bool deserialize(const QByteArray &data)
qint32 getDevSampleRate()
virtual quint64 getCenterFrequency() const
Center frequency exposed by the sink.
QString m_reverseAPIAddress
int getDeviceSetIndex() const
void * getBuddySharedPtr() const
uint16_t m_reverseAPIPort
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
DSPDeviceSourceEngine * getDeviceSourceEngine()
bool applySettings(const BladeRF1OutputSettings &settings, bool force)
void setReverseApiDeviceIndex(qint32 reverse_api_device_index)
void setBuddySharedPtr(void *ptr)
static const int m_sampleFifoMinSize
virtual int webapiRun(bool run, SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
void setBandwidth(qint32 bandwidth)
void setUseReverseApi(qint32 use_reverse_api)
void setXb200(qint32 xb200)
static bool match(const Message *message)
virtual int webapiRunGet(SWGSDRangel::SWGDeviceState &response, QString &errorMessage)
void setLog2Interpolation(unsigned int log2_interp)
void setVga1(qint32 vga1)
bladerf_xb200_filter m_xb200Filter
quint64 m_centerFrequency
void setVga2(qint32 vga2)
QString * getReverseApiAddress()
QNetworkAccessManager * m_networkManager
uint16_t m_reverseAPIDeviceIndex
void networkManagerFinished(QNetworkReply *reply)
void getDeviceEngineStateStr(QString &state)
void resize(uint32_t size)
const QString & getSamplingDeviceSerial() const
Bladerf1OutputThread * m_bladerfThread
QByteArray serialize() const
virtual int getSampleRate() const
Sample rate exposed by the sink.
DeviceBladeRF1Params m_sharedParams
void setXb200Path(qint32 xb200_path)
void webapiReverseSendSettings(QList< QString > &deviceSettingsKeys, const BladeRF1OutputSettings &settings, bool force)
struct bladerf * m_dev
device handle if the party has ownership else 0
void setCenterFrequency(qint64 center_frequency)
State state() const
Return DSP engine current state.
SampleSourceFifo m_sampleSourceFifo
const std::vector< DeviceAPI * > & getSourceBuddies() const
void setLog2Interp(qint32 log2_interp)
void setDevSampleRate(qint32 dev_sample_rate)
BladeRF1OutputSettings m_settings
void setDirection(qint32 direction)
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
virtual int webapiSettingsPutPatch(bool force, const QStringList &deviceSettingsKeys, SWGSDRangel::SWGDeviceSettings &response, QString &errorMessage)
void setXb200Filter(qint32 xb200_filter)
T max(const T &x, const T &y)
qint32 getReverseApiPort()
qint64 getCenterFrequency()
void setDeviceHwType(QString *device_hw_type)
static MsgStartStop * create(bool startStop)
virtual ~Bladerf1Output()
void webapiReverseSendStartStop(bool start)