22 #include <QNetworkReply> 44 m_deviceAPI(deviceAPI),
48 m_deviceDescription("BladeRFInput"),
52 m_fileSink =
new FileRecord(QString(
"test_%1.sdriq").
arg(m_deviceAPI->getDeviceUID()));
53 m_deviceAPI->setNbSourceStreams(1);
54 m_deviceAPI->addAncillarySink(m_fileSink);
56 m_deviceAPI->setBuddySharedPtr(&m_sharedParams);
58 m_networkManager =
new QNetworkAccessManager();
59 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
93 qCritical(
"BladerfInput::openDevice: could not allocate SampleFifo");
102 if (buddySharedParams == 0)
104 qCritical(
"BladerfInput::openDevice: could not get shared parameters from buddy");
108 if (buddySharedParams->
m_dev == 0)
110 qCritical(
"BladerfInput::openDevice: could not get BladeRF handle from buddy");
129 if ((res = bladerf_sync_config(
m_dev, BLADERF_RX_X1, BLADERF_FORMAT_SC16_Q11, 64, 8192, 32, 10000)) < 0)
131 qCritical(
"BladerfInput::start: bladerf_sync_config with return code %d", res);
135 if ((res = bladerf_enable_module(
m_dev, BLADERF_MODULE_RX,
true)) < 0)
137 qCritical(
"BladerfInput::start: bladerf_enable_module with return code %d", res);
155 qDebug(
"BladerfInput::start: no device handle");
170 qDebug(
"BladerfInput::startInput: started");
184 if ((res = bladerf_enable_module(
m_dev, BLADERF_MODULE_RX,
false)) < 0)
186 qCritical(
"BladerfInput::stop: bladerf_enable_module with return code %d", res);
191 qDebug(
"BladerfInput::closeDevice: closing device since Tx side is not open");
195 bladerf_close(
m_dev);
280 qDebug() <<
"Bladerf1Input::handleMessage: MsgConfigureBladerf1";
284 qDebug(
"BladeRF config error");
292 qDebug() <<
"BladerfInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
314 qDebug() <<
"BladerfInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
342 bool forwardChange =
false;
343 QList<QString> reverseAPIKeys;
346 qDebug() <<
"BladerfInput::applySettings: m_dev: " <<
m_dev;
349 reverseAPIKeys.append(
"dcBlock");
352 reverseAPIKeys.append(
"iqCorrection");
363 reverseAPIKeys.append(
"lnaGain");
368 qDebug(
"BladerfInput::applySettings: bladerf_set_lna_gain() failed");
370 qDebug() <<
"BladerfInput::applySettings: LNA gain set to " <<
getLnaGain(settings.
m_lnaGain);
377 reverseAPIKeys.append(
"vga1");
381 if(bladerf_set_rxvga1(
m_dev, settings.
m_vga1) != 0) {
382 qDebug(
"BladerfInput::applySettings: bladerf_set_rxvga1() failed");
384 qDebug() <<
"BladerfInput::applySettings: VGA1 gain set to " << settings.
m_vga1;
391 reverseAPIKeys.append(
"vga2");
395 if(bladerf_set_rxvga2(
m_dev, settings.
m_vga2) != 0) {
396 qDebug(
"BladerfInput::applySettings: bladerf_set_rxvga2() failed");
398 qDebug() <<
"BladerfInput::applySettings: VGA2 gain set to " << settings.
m_vga2;
405 reverseAPIKeys.append(
"xb200");
416 changeSettings =
false;
418 changeSettings =
true;
423 changeSettings =
true;
430 if (bladerf_expansion_attach(
m_dev, BLADERF_XB_200) != 0) {
431 qDebug(
"BladerfInput::applySettings: bladerf_expansion_attach(xb200) failed");
433 qDebug() <<
"BladerfInput::applySettings: Attach XB200";
438 if (bladerf_expansion_attach(
m_dev, BLADERF_XB_NONE) != 0) {
439 qDebug(
"BladerfInput::applySettings: bladerf_expansion_attach(none) failed");
441 qDebug() <<
"BladerfInput::applySettings: Detach XB200";
452 reverseAPIKeys.append(
"xb200Path");
456 if(bladerf_xb200_set_path(
m_dev, BLADERF_MODULE_RX, settings.
m_xb200Path) != 0) {
457 qDebug(
"BladerfInput::applySettings: bladerf_xb200_set_path(BLADERF_MODULE_RX) failed");
459 qDebug() <<
"BladerfInput::applySettings: set xb200 path to " << settings.
m_xb200Path;
466 reverseAPIKeys.append(
"xb200Filter");
470 if(bladerf_xb200_set_filterbank(
m_dev, BLADERF_MODULE_RX, settings.
m_xb200Filter) != 0) {
471 qDebug(
"BladerfInput::applySettings: bladerf_xb200_set_filterbank(BLADERF_MODULE_RX) failed");
473 qDebug() <<
"BladerfInput::applySettings: set xb200 filter to " << settings.
m_xb200Filter;
480 reverseAPIKeys.append(
"devSampleRate");
481 forwardChange =
true;
485 unsigned int actualSamplerate;
487 if (bladerf_set_sample_rate(
m_dev, BLADERF_MODULE_RX, settings.
m_devSampleRate, &actualSamplerate) < 0) {
488 qCritical(
"BladerfInput::applySettings: could not set sample rate: %d", settings.
m_devSampleRate);
490 qDebug() <<
"BladerfInput::applySettings: bladerf_set_sample_rate(BLADERF_MODULE_RX) actual sample rate is " << actualSamplerate;
497 reverseAPIKeys.append(
"bandwidth");
501 unsigned int actualBandwidth;
503 if( bladerf_set_bandwidth(
m_dev, BLADERF_MODULE_RX, settings.
m_bandwidth, &actualBandwidth) < 0) {
504 qCritical(
"BladerfInput::applySettings: could not set bandwidth: %d", settings.
m_bandwidth);
506 qDebug() <<
"BladerfInput::applySettings: bladerf_set_bandwidth(BLADERF_MODULE_RX) actual bandwidth is " << actualBandwidth;
513 reverseAPIKeys.append(
"fcPos");
518 qDebug() <<
"BladerfInput::applySettings: set fc pos (enum) to " << (int) settings.
m_fcPos;
524 reverseAPIKeys.append(
"log2Decim");
525 forwardChange =
true;
530 qDebug() <<
"BladerfInput::applySettings: set decimation to " << (1<<settings.
m_log2Decim);
535 reverseAPIKeys.append(
"centerFrequency");
549 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
552 forwardChange =
true;
556 if (bladerf_set_frequency(
m_dev, BLADERF_MODULE_RX, deviceCenterFrequency ) != 0) {
557 qWarning(
"BladerfInput::applySettings: bladerf_set_frequency(%lld) failed", settings.
m_centerFrequency);
559 qDebug(
"BladerfInput::applySettings: bladerf_set_frequency(%lld)", settings.
m_centerFrequency);
583 qDebug() <<
"BladerfInput::applySettings: " 605 return BLADERF_LNA_GAIN_MAX;
607 else if (lnaGain == 1)
609 return BLADERF_LNA_GAIN_MID;
613 return BLADERF_LNA_GAIN_BYPASS;
619 QString& errorMessage)
664 const QStringList& deviceSettingsKeys,
666 QString& errorMessage)
671 if (deviceSettingsKeys.contains(
"centerFrequency")) {
674 if (deviceSettingsKeys.contains(
"devSampleRate")) {
677 if (deviceSettingsKeys.contains(
"lnaGain")) {
680 if (deviceSettingsKeys.contains(
"vga1")) {
683 if (deviceSettingsKeys.contains(
"vga2")) {
686 if (deviceSettingsKeys.contains(
"bandwidth")) {
689 if (deviceSettingsKeys.contains(
"log2Decim")) {
692 if (deviceSettingsKeys.contains(
"fcPos")) {
695 if (deviceSettingsKeys.contains(
"xb200")) {
698 if (deviceSettingsKeys.contains(
"xb200Path")) {
701 if (deviceSettingsKeys.contains(
"xb200Filter")) {
704 if (deviceSettingsKeys.contains(
"dcBlock")) {
707 if (deviceSettingsKeys.contains(
"iqCorrection")) {
710 if (deviceSettingsKeys.contains(
"fileRecordName")) {
713 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
716 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
719 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
722 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
741 QString& errorMessage)
751 QString& errorMessage)
778 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
781 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
784 if (deviceSettingsKeys.contains(
"lnaGain") || force) {
787 if (deviceSettingsKeys.contains(
"vga1") || force) {
790 if (deviceSettingsKeys.contains(
"vga2") || force) {
793 if (deviceSettingsKeys.contains(
"bandwidth") || force) {
796 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
799 if (deviceSettingsKeys.contains(
"fcPos") || force) {
802 if (deviceSettingsKeys.contains(
"xb200") || force) {
805 if (deviceSettingsKeys.contains(
"xb200Path") || force) {
808 if (deviceSettingsKeys.contains(
"xb200Filter") || force) {
811 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
814 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
817 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
821 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
826 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
828 QBuffer *buffer=
new QBuffer();
829 buffer->open((QBuffer::ReadWrite));
830 buffer->write(swgDeviceSettings->
asJson().toUtf8());
836 delete swgDeviceSettings;
846 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
851 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
853 QBuffer *buffer=
new QBuffer();
854 buffer->open((QBuffer::ReadWrite));
855 buffer->write(swgDeviceSettings->
asJson().toUtf8());
864 delete swgDeviceSettings;
869 QNetworkReply::NetworkError replyError = reply->error();
873 qWarning() <<
"Bladerf1Input::networkManagerFinished:" 874 <<
" error(" << (int) replyError
875 <<
"): " << replyError
876 <<
": " << reply->errorString();
880 QString answer = reply->readAll();
882 qDebug(
"Bladerf1Input::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
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.
void setBladeRf1InputSettings(SWGBladeRF1InputSettings *blade_rf1_input_settings)
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.
State state() const
Return DSP engine current state.
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)
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.
SWGBladeRF1InputSettings * getBladeRf1InputSettings()
int getDeviceSetIndex() const
void * getBuddySharedPtr() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
void genUniqueFileName(uint deviceUID, int istream=-1)
DSPDeviceSinkEngine * getDeviceSinkEngine()
void setBuddySharedPtr(void *ptr)
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.
void getDeviceEngineStateStr(QString &state)
const QString & getSamplingDeviceSerial() const
struct bladerf * 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)
void setDirection(qint32 direction)
void setDeviceHwType(QString *device_hw_type)