22 #include <QMutexLocker> 24 #include <QNetworkReply> 51 m_deviceAPI(deviceAPI),
59 m_fileSink =
new FileRecord(QString(
"test_%1.sdriq").
arg(m_deviceAPI->getDeviceUID()));
60 m_deviceAPI->setNbSourceStreams(1);
61 m_deviceAPI->addAncillarySink(m_fileSink);
63 m_networkManager =
new QNetworkAccessManager();
64 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
90 qCritical(
"XTRXInput::openDevice: could not allocate SampleFifo");
95 qDebug(
"XTRXInput::openDevice: allocated SampleFifo");
101 qDebug(
"XTRXInput::openDevice: look in Rx buddies");
106 if (deviceXTRXShared == 0)
108 qCritical(
"XTRXInput::openDevice: the source buddy shared pointer is null");
116 qCritical(
"XTRXInput::openDevice: cannot get device pointer from Rx buddy");
125 qDebug(
"XTRXInput::openDevice: look in Tx buddies");
130 if (deviceXTRXShared == 0)
132 qCritical(
"XTRXInput::openDevice: the sink buddy shared pointer is null");
140 qCritical(
"XTRXInput::openDevice: cannot get device pointer from Tx buddy");
149 qDebug(
"XTRXInput::openDevice: open device here");
157 qCritical(
"XTRXInput::openDevice: cannot open BladeRF2 device");
208 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
210 for (; it != sourceBuddies.end(); ++it)
216 xtrxInputThread = buddySource->
getThread();
218 if (xtrxInputThread) {
224 return xtrxInputThread;
235 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
237 for (; it != sourceBuddies.end(); ++it)
277 qDebug(
"XTRXInput::start: no device object");
283 bool needsStart =
false;
287 qDebug(
"XTRXInput::start: thread is already allocated");
289 unsigned int nbOriginalChannels = xtrxInputThread->
getNbChannels();
293 if (nbOriginalChannels != 0)
295 qDebug(
"XTRXInput::start: expand channels. Re-allocate thread and take ownership");
298 unsigned int *log2Decims =
new unsigned int[2];
300 for (
int i = 0;
i < 2;
i++)
307 delete xtrxInputThread;
312 for (
int i = 0;
i < 2;
i++)
320 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
322 for (; it != sourceBuddies.end(); ++it)
336 qDebug(
"XTRXInput::start: keep buddy thread");
341 qDebug(
"XTRXInput::start: allocate thread and take ownership");
355 qDebug(
"XTRXInput::start: (re)start thread");
359 qDebug(
"XTRXInput::start: started");
381 int requestedChannel = removedChannel ^ 1;
384 if (xtrxInputThread == 0) {
390 if (nbOriginalChannels == 1)
392 qDebug(
"XTRXInput::stop: SI mode. Just stop and delete the thread");
394 delete xtrxInputThread;
400 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
402 for (; it != sourceBuddies.end(); ++it)
408 else if (nbOriginalChannels == 2)
410 qDebug(
"XTRXInput::stop: MI mode. Reduce by deleting and re-creating the thread");
412 delete xtrxInputThread;
422 std::vector<DeviceAPI*>::const_iterator it = sourceBuddies.begin();
424 for (; it != sourceBuddies.end(); ++it)
440 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
442 qDebug(
"XTRXInput::suspendTxThread (%lu)", sinkBuddies.size());
444 for (; itSink != sinkBuddies.end(); ++itSink)
463 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
465 qDebug(
"XTRXInput::resumeTxThread (%lu)", sinkBuddies.size());
467 for (; itSink != sinkBuddies.end(); ++itSink)
528 return devSampleRate;
539 return log2HardDecim;
581 qDebug(
"XTRXInput::getLORange: min: %f max: %f step: %f",
590 qDebug(
"XTRXInput::getSRRange: min: %f max: %f step: %f",
599 qDebug(
"XTRXInput::getLPRange: min: %f max: %f step: %f",
608 qDebug() <<
"XTRXInput::handleMessage: MsgConfigureXTRX";
612 qDebug(
"XTRXInput::handleMessage config error");
632 qDebug() <<
"XTRXInput::handleMessage: MsgReportBuddyChange:" 700 double board_temp = 0.0;
701 bool gps_locked =
false;
704 qDebug(
"XTRXInput::handleMessage: MsgGetDeviceInfo: cannot get board temperature");
708 qDebug(
"XTRXInput::handleMessage: MsgGetDeviceInfo: cannot get GPS lock status");
722 std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin();
724 for (; itSource != sourceBuddies.end(); ++itSource)
726 if ((*itSource)->getSamplingDeviceGUIMessageQueue())
729 (*itSource)->getSamplingDeviceGUIMessageQueue()->push(report);
735 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
737 for (; itSink != sinkBuddies.end(); ++itSink)
739 if ((*itSink)->getSamplingDeviceGUIMessageQueue())
742 (*itSink)->getSamplingDeviceGUIMessageQueue()->push(report);
751 qDebug() <<
"XTRXInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
764 qDebug() <<
"XTRXInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
786 static double tia_to_db(
unsigned idx)
813 qDebug(
"XTRXInput::apply_gain_lna: xtrx_set_gain(LNA) failed");
815 qDebug() <<
"XTRXInput::apply_gain_lna: Gain (LNA) set to " << gain;
826 qDebug(
"XTRXInput::apply_gain_tia: xtrx_set_gain(TIA) failed");
828 qDebug() <<
"XTRXInput::apply_gain_tia: Gain (TIA) set to " << gain;
840 qDebug(
"XTRXInput::apply_gain_pga: xtrx_set_gain(PGA) failed");
844 qDebug() <<
"XTRXInput::apply_gain_pga: Gain (PGA) set to " << gain;
852 QList<QString> reverseAPIKeys;
854 bool forwardChangeOwnDSP =
false;
855 bool forwardChangeRxDSP =
false;
856 bool forwardChangeAllDSP =
false;
857 bool forwardClockSource =
false;
858 bool rxThreadWasRunning =
false;
859 bool doLPCalibration =
false;
860 bool doChangeSampleRate =
false;
861 bool doChangeFreq =
false;
863 bool doGainAuto =
false;
864 bool doGainLna =
false;
865 bool doGainTia =
false;
866 bool doGainPga =
false;
872 <<
" sample rate with soft decimation: " <<
getSampleRate() <<
"S/s" 885 <<
" force: " << force
886 <<
" forceNCOFrequency: " << forceNCOFrequency
887 <<
" doLPCalibration: " << doLPCalibration;
891 reverseAPIKeys.append(
"dcBlock");
897 reverseAPIKeys.append(
"iqCorrection");
903 reverseAPIKeys.append(
"pwrmode");
912 qCritical(
"XTRXInput::applySettings: could not set power mode %d", settings.
m_pwrmode);
918 reverseAPIKeys.append(
"extClock");
921 reverseAPIKeys.append(
"extClockFreq");
931 (settings.
m_extClock) ? XTRX_CLKSRC_EXT : XTRX_CLKSRC_INT);
933 forwardClockSource =
true;
934 doChangeSampleRate =
true;
936 qDebug(
"XTRXInput::applySettings: clock set to %s (Ext: %d Hz)",
937 settings.
m_extClock ?
"external" :
"internal",
944 reverseAPIKeys.append(
"devSampleRate");
947 reverseAPIKeys.append(
"log2HardDecim");
953 forwardChangeAllDSP =
true;
956 doChangeSampleRate =
true;
961 reverseAPIKeys.append(
"gainMode");
964 reverseAPIKeys.append(
"gain");
967 reverseAPIKeys.append(
"lnaGain");
970 reverseAPIKeys.append(
"tiaGain");
973 reverseAPIKeys.append(
"pgaGain");
1013 reverseAPIKeys.append(
"lpfBW");
1016 doLPCalibration =
true;
1021 if ((
m_settings.m_lpfFIRBW != settings.m_lpfFIRBW) ||
1022 (
m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force)
1024 if (
m_deviceShared.m_deviceParams->getDevice() != 0 && m_channelAcquired)
1029 settings.m_lpfFIREnable,
1030 settings.m_lpfFIRBW) < 0)
1032 qCritical(
"XTRXInput::applySettings: could %s and set LPF FIR to %f Hz",
1033 settings.m_lpfFIREnable ?
"enable" :
"disable",
1034 settings.m_lpfFIRBW);
1039 qDebug(
"XTRXInput::applySettings: %sd and set LPF FIR to %f Hz",
1040 settings.m_lpfFIREnable ?
"enable" :
"disable",
1041 settings.m_lpfFIRBW);
1049 reverseAPIKeys.append(
"log2SoftDecim");
1050 forwardChangeOwnDSP =
true;
1052 if (inputThread != 0)
1055 qDebug() <<
"XTRXInput::applySettings: set soft decimation to " << (1<<settings.
m_log2SoftDecim);
1061 reverseAPIKeys.append(
"antennaPath");
1066 qCritical(
"XTRXInput::applySettings: could not set antenna path to %d", (
int) settings.
m_antennaPath);
1068 qDebug(
"XTRXInput::applySettings: set antenna path to %d", (
int) settings.
m_antennaPath);
1075 reverseAPIKeys.append(
"centerFrequency");
1076 doChangeFreq =
true;
1080 reverseAPIKeys.append(
"ncoFrequency");
1083 reverseAPIKeys.append(
"ncoEnable");
1089 forceNCOFrequency =
true;
1103 if (doChangeSampleRate)
1110 rxThreadWasRunning =
true;
1121 qCritical(
"XTRXInput::applySettings: could not set sample rate to %f with oversampling of %d",
1127 doChangeFreq =
true;
1128 forceNCOFrequency =
true;
1129 forwardChangeAllDSP =
true;
1131 qDebug(
"XTRXInput::applySettings: sample rate set to %f with oversampling of %d",
1138 if (rxThreadWasRunning) {
1143 if (doLPCalibration)
1149 qCritical(
"XTRXInput::applySettings: could not set LPF to %f Hz",
m_settings.
m_lpfBW);
1174 forwardChangeRxDSP =
true;
1182 qCritical(
"XTRXInput::applySettings: could not set frequency to %lu", settings.
m_centerFrequency);
1185 qDebug(
"XTRXInput::applySettings: frequency set to %lu", settings.
m_centerFrequency);
1190 if (forceNCOFrequency)
1200 qCritical(
"XTRXInput::applySettings: could not %s and set NCO to %d Hz",
1206 forwardChangeOwnDSP =
true;
1207 qDebug(
"XTRXInput::applySettings: %sd and set NCO to %d Hz",
1216 if (forwardChangeAllDSP)
1218 qDebug(
"XTRXInput::applySettings: forward change to all buddies");
1234 std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin();
1236 for (; itSource != sourceBuddies.end(); ++itSource)
1240 (*itSource)->getSamplingDeviceInputMessageQueue()->push(report);
1245 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
1247 for (; itSink != sinkBuddies.end(); ++itSink)
1251 (*itSink)->getSamplingDeviceInputMessageQueue()->push(report);
1254 else if (forwardChangeRxDSP)
1256 qDebug(
"XTRXInput::applySettings: forward change to Rx buddies");
1272 std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin();
1274 for (; itSource != sourceBuddies.end(); ++itSource)
1278 (*itSource)->getSamplingDeviceInputMessageQueue()->push(report);
1281 else if (forwardChangeOwnDSP)
1283 qDebug(
"XTRXInput::applySettings: forward change to self only");
1298 if (forwardClockSource)
1302 std::vector<DeviceAPI*>::const_iterator itSource = sourceBuddies.begin();
1304 for (; itSource != sourceBuddies.end(); ++itSource)
1308 (*itSource)->getSamplingDeviceInputMessageQueue()->push(report);
1313 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
1315 for (; itSink != sinkBuddies.end(); ++itSink)
1319 (*itSink)->getSamplingDeviceInputMessageQueue()->push(report);
1328 QString& errorMessage)
1330 (void) errorMessage;
1339 const QStringList& deviceSettingsKeys,
1341 QString& errorMessage)
1343 (void) errorMessage;
1346 if (deviceSettingsKeys.contains(
"centerFrequency")) {
1349 if (deviceSettingsKeys.contains(
"devSampleRate")) {
1352 if (deviceSettingsKeys.contains(
"log2HardDecim")) {
1355 if (deviceSettingsKeys.contains(
"dcBlock")) {
1358 if (deviceSettingsKeys.contains(
"iqCorrection")) {
1361 if (deviceSettingsKeys.contains(
"log2SoftDecim")) {
1364 if (deviceSettingsKeys.contains(
"lpfBW")) {
1367 if (deviceSettingsKeys.contains(
"gain")) {
1370 if (deviceSettingsKeys.contains(
"ncoEnable")) {
1373 if (deviceSettingsKeys.contains(
"ncoFrequency")) {
1376 if (deviceSettingsKeys.contains(
"antennaPath")) {
1379 if (deviceSettingsKeys.contains(
"gainMode")) {
1382 if (deviceSettingsKeys.contains(
"lnaGain")) {
1385 if (deviceSettingsKeys.contains(
"tiaGain")) {
1388 if (deviceSettingsKeys.contains(
"pgaGain")) {
1391 if (deviceSettingsKeys.contains(
"extClock")) {
1394 if (deviceSettingsKeys.contains(
"extClockFreq")) {
1397 if (deviceSettingsKeys.contains(
"pwrmode")) {
1400 if (deviceSettingsKeys.contains(
"fileRecordName")) {
1403 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
1406 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
1409 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
1412 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
1470 QString& errorMessage)
1472 (void) errorMessage;
1481 QString& errorMessage)
1483 (void) errorMessage;
1491 QString& errorMessage)
1493 (void) errorMessage;
1510 bool success =
false;
1512 bool gpsStatus =
false;
1519 XTRX_RX, XTRX_CH_AB, XTRX_PERF_LLFIFO, &fifolevel);
1520 success = (ret >= 0);
1543 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
1546 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
1549 if (deviceSettingsKeys.contains(
"log2HardDecim") || force) {
1552 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
1555 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
1558 if (deviceSettingsKeys.contains(
"log2SoftDecim") || force) {
1561 if (deviceSettingsKeys.contains(
"ncoEnable") || force) {
1564 if (deviceSettingsKeys.contains(
"ncoFrequency") || force) {
1567 if (deviceSettingsKeys.contains(
"lpfBW") || force) {
1570 if (deviceSettingsKeys.contains(
"antennaPath") || force) {
1573 if (deviceSettingsKeys.contains(
"gainMode") || force) {
1576 if (deviceSettingsKeys.contains(
"gain") || force) {
1579 if (deviceSettingsKeys.contains(
"lnaGain") || force) {
1582 if (deviceSettingsKeys.contains(
"tiaGain") || force) {
1585 if (deviceSettingsKeys.contains(
"pgaGain") || force) {
1588 if (deviceSettingsKeys.contains(
"extClock") || force) {
1591 if (deviceSettingsKeys.contains(
"extClockFreq") || force) {
1594 if (deviceSettingsKeys.contains(
"pwrmode") || force) {
1597 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
1601 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
1606 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
1608 QBuffer *buffer=
new QBuffer();
1609 buffer->open((QBuffer::ReadWrite));
1610 buffer->write(swgDeviceSettings->
asJson().toUtf8());
1616 delete swgDeviceSettings;
1626 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
1631 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
1633 QBuffer *buffer=
new QBuffer();
1634 buffer->open((QBuffer::ReadWrite));
1635 buffer->write(swgDeviceSettings->
asJson().toUtf8());
1644 delete swgDeviceSettings;
1649 QNetworkReply::NetworkError replyError = reply->error();
1653 qWarning() <<
"XTRXInput::networkManagerFinished:" 1654 <<
" error(" << (int) replyError
1655 <<
"): " << replyError
1656 <<
": " << reply->errorString();
1660 QString answer = reply->readAll();
1662 qDebug(
"XTRXInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
virtual bool isRunning()=0
uint64_t getCenterFrequency() const
void push(Message *message, bool emitSignal=true)
Push message onto queue.
void stopDeviceEngine()
Stop the device engine corresponding to the stream type.
void setXtrxInputSettings(SWGXtrxInputSettings *xtrx_input_settings)
const std::vector< DeviceAPI * > & getSinkBuddies() const
static MsgReportClockSourceChange * create(bool extClock, uint32_t m_extClockFreq)
MessageQueue m_inputMessageQueue
Input queue to the source.
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
uint32_t getExtClockFeq() const
double getClockGen() const
int getDevSampleRate() const
uint32_t getDeviceItemIndex() const
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
double set_samplerate(double rate, double master, bool output)
void setOriginatorIndex(qint32 originator_index)
SampleSinkFifo m_sampleFifo
struct xtrx_dev * getDevice()
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
bool m_threadWasRunning
flag to know if thread needs to be resumed after suspend
void * getBuddySharedPtr() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
SWGXtrxInputSettings * getXtrxInputSettings()
double getActualInputRate() const
void setBuddySharedPtr(void *ptr)
double get_board_temperature()
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.
virtual void startWork()=0
int m_channel
allocated channel (-1 if none)
unsigned getLog2HardDecimInterp() const
void getDeviceEngineStateStr(QString &state)
const QString & getSamplingDeviceSerial() const
static MsgReportBuddyChange * create(int devSampleRate, unsigned log2HardDecimInterp, uint64_t centerFrequency, bool rxElseTx)
void setXtrxInputReport(SWGXtrxInputReport *xtrx_input_report)
SWGXtrxInputReport * getXtrxInputReport()
const std::vector< DeviceAPI * > & getSourceBuddies() const
ThreadInterface * m_thread
holds the thread address if started else 0
static void getAutoGains(uint32_t autoGain, uint32_t &lnaGain, uint32_t &tiaGain, uint32_t &pgaGain)
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
virtual void stopWork()=0
bool open(const char *deviceStr)
void setDirection(qint32 direction)
static MsgReportDeviceInfo * create(float temperature, bool gpsLocked)
void setDeviceHwType(QString *device_hw_type)
MessageQueue * getSamplingDeviceGUIMessageQueue()
Sampling device (ex: single Tx) GUI input message queue.
unsigned __int64 uint64_t