19 #include <QNetworkReply> 22 #include "libbladeRF.h" 47 m_deviceAPI(deviceAPI),
55 if (m_deviceShared.m_dev)
57 const bladerf_gain_modes *modes = 0;
58 int nbModes = m_deviceShared.m_dev->getGainModesRx(&modes);
62 for (
int i = 0;
i < nbModes;
i++) {
63 m_gainModes.push_back(
GainMode{QString(modes[
i].name), modes[
i].mode});
68 m_fileSink =
new FileRecord(QString(
"test_%1.sdriq").
arg(m_deviceAPI->getDeviceUID()));
69 m_deviceAPI->setNbSourceStreams(1);
70 m_deviceAPI->addAncillarySink(m_fileSink);
71 m_networkManager =
new QNetworkAccessManager();
72 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
98 qCritical(
"BladeRF2Input::openDevice: could not allocate SampleFifo");
103 qDebug(
"BladeRF2Input::openDevice: allocated SampleFifo");
109 qDebug(
"BladeRF2Input::openDevice: look in Rx buddies");
114 if (deviceBladeRF2Shared == 0)
116 qCritical(
"BladeRF2Input::openDevice: the source buddy shared pointer is null");
124 qCritical(
"BladeRF2Input::openDevice: cannot get device pointer from Rx buddy");
133 qDebug(
"BladeRF2Input::openDevice: look in Tx buddies");
138 if (deviceBladeRF2Shared == 0)
140 qCritical(
"BladeRF2Input::openDevice: the sink buddy shared pointer is null");
148 qCritical(
"BladeRF2Input::openDevice: cannot get device pointer from Tx buddy");
157 qDebug(
"BladeRF2Input::openDevice: open device here");
165 qCritical(
"BladeRF2Input::openDevice: cannot open BladeRF2 device");
216 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
218 for (; it != sourceBuddies.end(); ++it)
224 bladerf2InputThread = buddySource->
getThread();
226 if (bladerf2InputThread) {
232 return bladerf2InputThread;
243 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
245 for (; it != sourceBuddies.end(); ++it)
291 qDebug(
"BladeRF2Input::start: no device object");
297 bool needsStart =
false;
299 if (bladerf2InputThread)
301 qDebug(
"BladeRF2Input::start: thread is already allocated");
303 int nbOriginalChannels = bladerf2InputThread->
getNbChannels();
305 if (requestedChannel+1 > nbOriginalChannels)
307 qDebug(
"BladeRF2Input::start: expand channels. Re-allocate thread and take ownership");
310 unsigned int *log2Decims =
new unsigned int[nbOriginalChannels];
311 int *fcPoss =
new int[nbOriginalChannels];
313 for (
int i = 0;
i < nbOriginalChannels;
i++)
315 fifos[
i] = bladerf2InputThread->
getFifo(
i);
321 delete bladerf2InputThread;
325 for (
int i = 0;
i < nbOriginalChannels;
i++)
327 bladerf2InputThread->
setFifo(
i, fifos[
i]);
329 bladerf2InputThread->
setFcPos(i, fcPoss[i]);
334 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
336 for (; it != sourceBuddies.end(); ++it) {
349 qDebug(
"BladeRF2Input::start: keep buddy thread");
354 qDebug(
"BladeRF2Input::start: allocate thread and take ownership");
366 qDebug(
"BladeRF2Input::start: enabling channel(s) and (re)sart buddy thread");
370 for (
int i = 0;
i < nbChannels;
i++)
373 qCritical(
"BladeRF2Input::start: channel %u cannot be enabled",
i);
382 qDebug(
"BladeRF2Input::start: started");
413 if (bladerf2InputThread == 0) {
417 int nbOriginalChannels = bladerf2InputThread->
getNbChannels();
419 if (nbOriginalChannels == 1)
421 qDebug(
"BladeRF2Input::stop: SI mode. Just stop and delete the thread");
423 delete bladerf2InputThread;
428 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
430 for (; it != sourceBuddies.end(); ++it) {
436 else if (requestedChannel == nbOriginalChannels - 1)
438 qDebug(
"BladeRF2Input::stop: MI mode. Reduce by deleting and re-creating the thread");
441 unsigned int *log2Decims =
new unsigned int[nbOriginalChannels-1];
442 int *fcPoss =
new int[nbOriginalChannels-1];
443 bool stillActiveFIFO =
false;
445 for (
int i = 0;
i < nbOriginalChannels-1;
i++)
447 fifos[
i] = bladerf2InputThread->
getFifo(
i);
448 stillActiveFIFO = stillActiveFIFO || (bladerf2InputThread->
getFifo(
i) != 0);
453 delete bladerf2InputThread;
461 for (
int i = 0;
i < nbOriginalChannels-1;
i++)
463 bladerf2InputThread->
setFifo(
i, fifos[
i]);
465 bladerf2InputThread->
setFcPos(i, fcPoss[i]);
470 qDebug(
"BladeRF2Input::stop: do not re-create thread as there are no more FIFOs active");
475 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
477 for (; it != sourceBuddies.end(); ++it) {
483 if (stillActiveFIFO) {
494 qDebug(
"BladeRF2Input::stop: MI mode. Not changing MI configuration. Just remove FIFO reference");
495 bladerf2InputThread->
setFifo(requestedChannel, 0);
561 qint64 df = ((qint64)freq_hz * loPpmTenths) / 10000000LL;
564 int status = bladerf_set_frequency(dev, BLADERF_CHANNEL_RX(requestedChannel), freq_hz);
567 qWarning(
"BladeRF2Input::setDeviceCenterFrequency: bladerf_set_frequency(%lld) failed: %s",
568 freq_hz, bladerf_strerror(status));
573 qDebug(
"BladeRF2Input::setDeviceCenterFrequency: bladerf_set_frequency(%lld)", freq_hz);
611 qDebug() <<
"BladeRF2Input::handleMessage: MsgConfigureBladeRF2";
615 qDebug(
"BladeRF2Input::handleMessage: MsgConfigureBladeRF2 config error");
626 unsigned int tmp_uint;
648 status = bladerf_get_bandwidth(dev, BLADERF_CHANNEL_RX(requestedChannel), &tmp_uint);
651 qCritical(
"BladeRF2Input::handleMessage: MsgReportBuddyChange: bladerf_get_bandwidth error: %s", bladerf_strerror(status));
656 status = bladerf_get_bias_tee(dev, BLADERF_CHANNEL_RX(requestedChannel), &tmp_bool);
659 qCritical(
"BladeRF2Input::handleMessage: MsgReportBuddyChange: bladerf_get_bias_tee error: %s", bladerf_strerror(status));
681 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
720 qDebug() <<
"BladeRF2Input::handleMessage: MsgFileRecord: " << conf.
getStartStop();
742 qDebug() <<
"BladeRF2Input::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
770 bool forwardChangeOwnDSP =
false;
771 bool forwardChangeRxBuddies =
false;
772 bool forwardChangeTxBuddies =
false;
778 xlatedDeviceCenterFrequency = xlatedDeviceCenterFrequency < 0 ? 0 : xlatedDeviceCenterFrequency;
779 QList<QString> reverseAPIKeys;
782 reverseAPIKeys.append(
"dcBlock");
785 reverseAPIKeys.append(
"iqCorrection");
796 reverseAPIKeys.append(
"devSampleRate");
797 forwardChangeOwnDSP =
true;
798 forwardChangeRxBuddies =
true;
799 forwardChangeTxBuddies =
true;
803 unsigned int actualSamplerate;
804 int status = bladerf_set_sample_rate(dev, BLADERF_CHANNEL_RX(requestedChannel), settings.
m_devSampleRate, &actualSamplerate);
808 qCritical(
"BladeRF2Input::applySettings: could not set sample rate: %d: %s",
813 qDebug() <<
"BladeRF2Input::applySettings: bladerf_set_sample_rate: actual sample rate is " << actualSamplerate;
820 reverseAPIKeys.append(
"bandwidth");
821 forwardChangeRxBuddies =
true;
825 unsigned int actualBandwidth;
826 int status = bladerf_set_bandwidth(dev, BLADERF_CHANNEL_RX(requestedChannel), settings.
m_bandwidth, &actualBandwidth);
830 qCritical(
"BladeRF2Input::applySettings: could not set bandwidth: %d: %s",
835 qDebug() <<
"BladeRF2Input::applySettings: bladerf_set_bandwidth: actual bandwidth is " << actualBandwidth;
842 reverseAPIKeys.append(
"fcPos");
845 if (inputThread != 0)
848 qDebug() <<
"BladeRF2Input::applySettings: set fc pos (enum) to " << (int) settings.
m_fcPos;
854 reverseAPIKeys.append(
"log2Decim");
855 forwardChangeOwnDSP =
true;
858 if (inputThread != 0)
861 qDebug() <<
"BladeRF2Input::applySettings: set decimation to " << (1<<settings.
m_log2Decim);
866 reverseAPIKeys.append(
"centerFrequency");
869 reverseAPIKeys.append(
"transverterMode");
872 reverseAPIKeys.append(
"transverterDeltaFrequency");
875 reverseAPIKeys.append(
"LOppmTenths");
878 reverseAPIKeys.append(
"devSampleRate");
890 xlatedDeviceCenterFrequency,
895 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
898 forwardChangeOwnDSP =
true;
899 forwardChangeRxBuddies =
true;
918 reverseAPIKeys.append(
"biasTee");
919 forwardChangeRxBuddies =
true;
925 reverseAPIKeys.append(
"gainMode");
926 forwardChangeRxBuddies =
true;
930 int status = bladerf_set_gain_mode(dev, BLADERF_CHANNEL_RX(requestedChannel), (bladerf_gain_mode) settings.
m_gainMode);
933 qWarning(
"BladeRF2Input::applySettings: bladerf_set_gain_mode(%d) failed: %s",
934 settings.
m_gainMode, bladerf_strerror(status));
936 qDebug(
"BladeRF2Input::applySettings: bladerf_set_gain_mode(%d)", settings.
m_gainMode);
942 reverseAPIKeys.append(
"globalGain");
945 reverseAPIKeys.append(
"gainMode");
951 forwardChangeRxBuddies =
true;
956 int status = bladerf_set_gain(dev, BLADERF_CHANNEL_RX(requestedChannel), settings.
m_globalGain);
959 qWarning(
"BladeRF2Input::applySettings: bladerf_set_gain(%d) failed: %s",
962 qDebug(
"BladeRF2Input::applySettings: bladerf_set_gain(%d)", settings.
m_globalGain);
967 if (forwardChangeOwnDSP)
975 if (forwardChangeRxBuddies)
979 std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin();
981 for (; itSource != sourceBuddies.end(); ++itSource)
989 (*itSource)->getSamplingDeviceInputMessageQueue()->push(report);
993 if (forwardChangeTxBuddies)
997 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
999 for (; itSink != sinkBuddies.end(); ++itSink)
1007 (*itSink)->getSamplingDeviceInputMessageQueue()->push(report);
1022 qDebug() <<
"BladeRF2Input::applySettings: " 1042 QString& errorMessage)
1044 (void) errorMessage;
1053 const QStringList& deviceSettingsKeys,
1055 QString& errorMessage)
1057 (void) errorMessage;
1060 if (deviceSettingsKeys.contains(
"centerFrequency")) {
1063 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
1066 if (deviceSettingsKeys.contains(
"devSampleRate")) {
1069 if (deviceSettingsKeys.contains(
"bandwidth")) {
1072 if (deviceSettingsKeys.contains(
"log2Decim")) {
1075 if (deviceSettingsKeys.contains(
"fcPos")) {
1078 if (deviceSettingsKeys.contains(
"dcBlock")) {
1081 if (deviceSettingsKeys.contains(
"iqCorrection")) {
1084 if (deviceSettingsKeys.contains(
"biasTee")) {
1087 if (deviceSettingsKeys.contains(
"gainMode")) {
1090 if (deviceSettingsKeys.contains(
"globalGain")) {
1093 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency")) {
1096 if (deviceSettingsKeys.contains(
"transverterMode")) {
1099 if (deviceSettingsKeys.contains(
"fileRecordName")) {
1102 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
1105 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
1108 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
1111 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
1130 (void) errorMessage;
1211 std::vector<GainMode>::const_iterator it = modes.begin();
1213 for (; it != modes.end(); ++it)
1224 QString& errorMessage)
1226 (void) errorMessage;
1234 QString& errorMessage)
1236 (void) errorMessage;
1261 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
1264 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
1267 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
1270 if (deviceSettingsKeys.contains(
"fcPos") || force) {
1273 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
1276 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
1279 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency") || force) {
1282 if (deviceSettingsKeys.contains(
"transverterMode") || force) {
1285 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
1288 if (deviceSettingsKeys.contains(
"devSampleRate")) {
1291 if (deviceSettingsKeys.contains(
"bandwidth")) {
1294 if (deviceSettingsKeys.contains(
"biasTee")) {
1297 if (deviceSettingsKeys.contains(
"gainMode")) {
1300 if (deviceSettingsKeys.contains(
"globalGain")) {
1304 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
1309 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
1311 QBuffer *buffer=
new QBuffer();
1312 buffer->open((QBuffer::ReadWrite));
1313 buffer->write(swgDeviceSettings->
asJson().toUtf8());
1319 delete swgDeviceSettings;
1329 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
1334 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
1336 QBuffer *buffer=
new QBuffer();
1337 buffer->open((QBuffer::ReadWrite));
1338 buffer->write(swgDeviceSettings->
asJson().toUtf8());
1347 delete swgDeviceSettings;
1352 QNetworkReply::NetworkError replyError = reply->error();
1356 qWarning() <<
"BladeRF2Input::networkManagerFinished:" 1357 <<
" error(" << (int) replyError
1358 <<
"): " << replyError
1359 <<
": " << reply->errorString();
1363 QString answer = reply->readAll();
1365 qDebug(
"BladeRF2Input::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.
SWGBladeRF2InputReport * getBladeRf2InputReport()
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
uint32_t getDeviceItemIndex() const
void setStep(qint32 step)
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
void setOriginatorIndex(qint32 originator_index)
void getBandwidthRangeRx(int &min, int &max, int &step)
SampleSinkFifo m_sampleFifo
MessageQueue * getMessageQueueToGUI()
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 getFrequencyRangeRx(uint64_t &min, uint64_t &max, int &step)
void getSampleRateRangeRx(int &min, int &max, int &step)
void setBuddySharedPtr(void *ptr)
int getLOppmTenths() const
static bool match(const Message *message)
void setBiasTeeRx(bool enable)
void removeAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Removes it.
void setBladeRf2InputSettings(SWGBladeRF2InputSettings *blade_rf2_input_settings)
static MsgReportBuddyChange * create(uint64_t centerFrequency, int LOppmTenths, int fcPos, int devSampleRate, bool rxElseTx)
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
void setBladeRf2InputReport(SWGBladeRF2InputReport *blade_rf2_input_report)
void getDeviceEngineStateStr(QString &state)
const QString & getSamplingDeviceSerial() const
int m_channel
allocated channel (-1 if none)
bool open(const char *serial)
uint64_t getCenterFrequency() const
void setStep(qint32 step)
void closeRx(int channel)
const std::vector< DeviceAPI * > & getSourceBuddies() const
int getDevSampleRate() const
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
void setDirection(qint32 direction)
void getGlobalGainRangeRx(int &min, int &max, int &step)
T max(const T &x, const T &y)
SWGBladeRF2InputSettings * getBladeRf2InputSettings()
void setDeviceHwType(QString *device_hw_type)
T min(const T &x, const T &y)
unsigned __int64 uint64_t