19 #include <QNetworkReply> 37 #define PLUTOSDR_BLOCKSIZE_SAMPLES (16*1024) //complex samples per buffer (must be multiple of 64) 44 m_deviceAPI(deviceAPI),
49 m_plutoSDRInputThread(0)
51 m_deviceSampleRates.m_addaConnvRate = 0;
52 m_deviceSampleRates.m_bbRateHz = 0;
53 m_deviceSampleRates.m_firRate = 0;
54 m_deviceSampleRates.m_hb1Rate = 0;
55 m_deviceSampleRates.m_hb2Rate = 0;
56 m_deviceSampleRates.m_hb3Rate = 0;
62 m_fileSink =
new FileRecord(QString(
"test_%1.sdriq").
arg(m_deviceAPI->getDeviceUID()));
63 m_deviceAPI->setNbSourceStreams(1);
64 m_deviceAPI->addAncillarySink(m_fileSink);
66 m_networkManager =
new QNetworkAccessManager();
67 connect(m_networkManager, SIGNAL(finished(QNetworkReply*)),
this, SLOT(networkManagerFinished(QNetworkReply*)));
102 qDebug(
"PlutoSDRInput::start: thread created");
189 qDebug() <<
"PlutoSDRInput::handleMessage: MsgConfigurePlutoSDR";
193 qDebug(
"PlutoSDRInput::handleMessage config error");
201 qDebug() <<
"PlutoSDRInput::handleMessage: MsgFileRecord: " << conf.
getStartStop();
223 qDebug() <<
"PlutoSDRInput::handleMessage: MsgStartStop: " << (cmd.
getStartStop() ?
"start" :
"stop");
266 qCritical(
"PlutoSDRInput::openDevice: could not allocate SampleFifo");
271 qDebug(
"PlutoSDRInput::openDevice: allocated SampleFifo");
277 qDebug(
"PlutoSDRInput::openDevice: look at Tx buddy");
285 qCritical(
"PlutoSDRInput::openDevice: cannot get device parameters from Tx buddy");
290 qDebug(
"PlutoSDRInput::openDevice: getting device parameters from Tx buddy");
297 qDebug(
"PlutoSDRInput::openDevice: open device here");
361 bool forwardChangeOwnDSP =
false;
362 bool forwardChangeOtherDSP =
false;
363 bool ownThreadWasRunning =
false;
364 bool suspendAllOtherThreads =
false;
367 QList<QString> reverseAPIKeys;
389 <<
" force: " << force;
392 reverseAPIKeys.append(
"centerFrequency");
395 reverseAPIKeys.append(
"devSampleRate");
398 reverseAPIKeys.append(
"LOppmTenths");
401 reverseAPIKeys.append(
"dcBlock");
404 reverseAPIKeys.append(
"iqCorrection");
407 reverseAPIKeys.append(
"hwBBDCBlock");
410 reverseAPIKeys.append(
"hwRFDCBlock");
413 reverseAPIKeys.append(
"hwIQCorrection");
416 reverseAPIKeys.append(
"lpfFIREnable");
419 reverseAPIKeys.append(
"lpfFIRBW");
422 reverseAPIKeys.append(
"lpfFIRlog2Decim");
425 reverseAPIKeys.append(
"lpfFIRGain");
428 reverseAPIKeys.append(
"log2Decim");
431 reverseAPIKeys.append(
"fcPos");
434 reverseAPIKeys.append(
"lpfBW");
437 reverseAPIKeys.append(
"gain");
440 reverseAPIKeys.append(
"antennaPath");
443 reverseAPIKeys.append(
"gainMode");
446 reverseAPIKeys.append(
"transverterMode");
449 reverseAPIKeys.append(
"transverterDeltaFrequency");
452 reverseAPIKeys.append(
"fileRecordName");
469 suspendAllOtherThreads =
true;
472 if (suspendAllOtherThreads)
475 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
477 for (; itSink != sinkBuddies.end(); ++itSink)
495 ownThreadWasRunning =
true;
525 forwardChangeOtherDSP =
true;
534 qDebug() <<
"PlutoSDRInput::applySettings: set soft decimation to " << (1<<settings.
m_log2Decim);
537 forwardChangeOwnDSP =
true;
543 forwardChangeOtherDSP =
true;
546 std::vector<std::string> params;
547 bool paramsToSet =
false;
562 DeviceSampleSource::FrequencyShiftScheme::FSHIFT_STD,
565 params.push_back(QString(tr(
"out_altvoltage0_RX_LO_frequency=%1").
arg(deviceCenterFrequency)).toStdString());
567 forwardChangeOwnDSP =
true;
574 qDebug() <<
"PlutoSDRInput::applySettings: set fcPos to " << settings.
m_fcPos;
581 params.push_back(QString(tr(
"in_voltage_rf_bandwidth=%1").
arg(settings.
m_lpfBW)).toStdString());
589 params.push_back(QString(tr(
"in_voltage0_rf_port_select=%1").
arg(rfPortStr)).toStdString());
597 params.push_back(QString(tr(
"in_voltage0_gain_control_mode=%1").
arg(gainModeStr)).toStdString());
603 params.push_back(QString(tr(
"in_voltage0_hardwaregain=%1").
arg(settings.
m_gain)).toStdString());
609 params.push_back(QString(tr(
"in_voltage_bb_dc_offset_tracking_en=%1").
arg(settings.
m_hwBBDCBlock ? 1 : 0)).toStdString());
615 params.push_back(QString(tr(
"in_voltage_rf_dc_offset_tracking_en=%1").
arg(settings.
m_hwRFDCBlock ? 1 : 0)).toStdString());
621 params.push_back(QString(tr(
"in_voltage_quadrature_tracking_en=%1").
arg(settings.
m_hwIQCorrection ? 1 : 0)).toStdString());
641 if (suspendAllOtherThreads)
644 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
646 for (; itSink != sinkBuddies.end(); ++itSink)
656 if (ownThreadWasRunning) {
661 if (forwardChangeOtherDSP)
664 qDebug(
"PlutoSDRInput::applySettings: forwardChangeOtherDSP");
667 std::vector<DeviceAPI*>::const_iterator itSink = sinkBuddies.begin();
669 for (; itSink != sinkBuddies.end(); ++itSink)
678 if ((*itSink)->getSamplingDeviceGUIMessageQueue())
681 (*itSink)->getSamplingDeviceGUIMessageQueue()->push(msgToGUI);
684 (*itSink)->getSamplingDeviceInputMessageQueue()->push(msg);
688 if (forwardChangeOwnDSP)
690 qDebug(
"PlutoSDRInput::applySettings: forward change to self");
753 QString& errorMessage)
763 QString& errorMessage)
781 QString& errorMessage)
792 const QStringList& deviceSettingsKeys,
794 QString& errorMessage)
799 if (deviceSettingsKeys.contains(
"centerFrequency")) {
802 if (deviceSettingsKeys.contains(
"devSampleRate")) {
805 if (deviceSettingsKeys.contains(
"LOppmTenths")) {
808 if (deviceSettingsKeys.contains(
"lpfFIREnable")) {
811 if (deviceSettingsKeys.contains(
"lpfFIRBW")) {
814 if (deviceSettingsKeys.contains(
"lpfFIRlog2Decim")) {
817 if (deviceSettingsKeys.contains(
"lpfFIRGain")) {
820 if (deviceSettingsKeys.contains(
"fcPos")) {
822 fcPos = fcPos < 0 ? 0 : fcPos > 2 ? 2 : fcPos;
825 if (deviceSettingsKeys.contains(
"dcBlock")) {
828 if (deviceSettingsKeys.contains(
"iqCorrection")) {
831 if (deviceSettingsKeys.contains(
"hwBBDCBlock")) {
834 if (deviceSettingsKeys.contains(
"hwRFDCBlock")) {
837 if (deviceSettingsKeys.contains(
"hwIQCorrection")) {
840 if (deviceSettingsKeys.contains(
"log2Decim")) {
843 if (deviceSettingsKeys.contains(
"lpfBW")) {
846 if (deviceSettingsKeys.contains(
"gain")) {
849 if (deviceSettingsKeys.contains(
"antennaPath")) {
854 if (deviceSettingsKeys.contains(
"gainMode")) {
859 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency")) {
862 if (deviceSettingsKeys.contains(
"transverterMode")) {
865 if (deviceSettingsKeys.contains(
"fileRecordName")) {
868 if (deviceSettingsKeys.contains(
"useReverseAPI")) {
871 if (deviceSettingsKeys.contains(
"reverseAPIAddress")) {
874 if (deviceSettingsKeys.contains(
"reverseAPIPort")) {
877 if (deviceSettingsKeys.contains(
"reverseAPIDeviceIndex")) {
896 QString& errorMessage)
970 if (deviceSettingsKeys.contains(
"centerFrequency") || force) {
973 if (deviceSettingsKeys.contains(
"devSampleRate") || force) {
976 if (deviceSettingsKeys.contains(
"LOppmTenths") || force) {
979 if (deviceSettingsKeys.contains(
"lpfFIREnable") || force) {
982 if (deviceSettingsKeys.contains(
"lpfFIRBW") || force) {
985 if (deviceSettingsKeys.contains(
"lpfFIRlog2Decim") || force) {
988 if (deviceSettingsKeys.contains(
"lpfFIRGain") || force) {
991 if (deviceSettingsKeys.contains(
"fcPos") || force) {
994 if (deviceSettingsKeys.contains(
"dcBlock") || force) {
997 if (deviceSettingsKeys.contains(
"iqCorrection") || force) {
1000 if (deviceSettingsKeys.contains(
"hwBBDCBlock") || force) {
1003 if (deviceSettingsKeys.contains(
"hwRFDCBlock") || force) {
1006 if (deviceSettingsKeys.contains(
"hwIQCorrection") || force) {
1009 if (deviceSettingsKeys.contains(
"log2Decim") || force) {
1012 if (deviceSettingsKeys.contains(
"lpfBW") || force) {
1015 if (deviceSettingsKeys.contains(
"gain") || force) {
1018 if (deviceSettingsKeys.contains(
"antennaPath") || force) {
1021 if (deviceSettingsKeys.contains(
"gainMode") || force) {
1024 if (deviceSettingsKeys.contains(
"transverterDeltaFrequency") || force) {
1027 if (deviceSettingsKeys.contains(
"transverterMode") || force) {
1030 if (deviceSettingsKeys.contains(
"fileRecordName") || force) {
1034 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/settings")
1039 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
1041 QBuffer *buffer=
new QBuffer();
1042 buffer->open((QBuffer::ReadWrite));
1043 buffer->write(swgDeviceSettings->
asJson().toUtf8());
1049 delete swgDeviceSettings;
1059 QString deviceSettingsURL = QString(
"http://%1:%2/sdrangel/deviceset/%3/device/run")
1064 m_networkRequest.setHeader(QNetworkRequest::ContentTypeHeader,
"application/json");
1066 QBuffer *buffer=
new QBuffer();
1067 buffer->open((QBuffer::ReadWrite));
1068 buffer->write(swgDeviceSettings->
asJson().toUtf8());
1077 delete swgDeviceSettings;
1082 QNetworkReply::NetworkError replyError = reply->error();
1086 qWarning() <<
"PlutoSDRInput::networkManagerFinished:" 1087 <<
" error(" << (int) replyError
1088 <<
"): " << replyError
1089 <<
": " << reply->errorString();
1093 QString answer = reply->readAll();
1095 qDebug(
"PlutoSDRInput::networkManagerFinished: reply:\n%s", answer.toStdString().c_str());
bool getRxGain(int &gaindB, unsigned int chan)
void getRxLORange(uint64_t &minLimit, uint64_t &maxLimit)
bool startDeviceEngine()
Start the device engine corresponding to the stream type.
void setSampleRate(uint32_t sampleRate)
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.
uint32_t getLpfFiRlog2IntDec() const
void setFileName(const QString &filename)
uint getDeviceUID() const
Return the current device engine unique ID.
bool m_threadWasRunning
flag to know if thread needs to be resumed after suspend
const std::vector< DeviceAPI * > & getSinkBuddies() const
MessageQueue m_inputMessageQueue
Input queue to the source.
bool isLpfFirEnable() const
virtual QString asJson() override
MessageQueue * getDeviceEngineInputMessageQueue()
Device engine message queue.
ThreadInterface * m_thread
holds the thread address if started else 0
bool initDeviceEngine()
Init the device engine corresponding to the stream type.
bool getRxRSSI(std::string &rssiStr, unsigned int chan)
void setOriginatorIndex(qint32 originator_index)
DevicePlutoSDRParams * m_deviceParams
unique hardware device parameters
void getbbLPRxRange(uint32_t &minLimit, uint32_t &maxLimit)
bool open(const std::string &serial)
uint32_t m_hb3Rate
Rate of the HB3/(DEC3 or INT3) filter (Rx: out, Tx: in) - this is the HB2 working sample rate...
SampleSinkFifo m_sampleFifo
static MsgCrossReportToBuddy * create(uint64_t devSampleRate, bool lpfFIREnable, uint32_t lpfFIRlog2Interp, uint32_t lpfFIRBW, int32_t loPPMTenths)
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.
void setFIREnable(bool enable)
int getDeviceSetIndex() const
void * getBuddySharedPtr() const
#define MESSAGE_CLASS_DEFINITION(Name, BaseClass)
void genUniqueFileName(uint deviceUID, int istream=-1)
struct iio_buffer * createRxBuffer(unsigned int size, bool cyclic)
void setLOPPMTenths(int ppmTenths)
bool getRxSampleRates(SampleRates &sampleRates)
void setFIR(uint32_t sampleRate, uint32_t intdec, DeviceUse use, uint32_t bw, int gain)
SWGPlutoSdrInputReport * getPlutoSdrInputReport()
void setBuddySharedPtr(void *ptr)
virtual void stopWork()=0
static bool match(const Message *message)
uint32_t getLpfFirbw() const
void removeAncillarySink(BasebandSampleSink *sink, unsigned int index=0)
Removes it.
int32_t getLoPPMTenths() const
MessageQueue * m_guiMessageQueue
Input message queue to the GUI.
uint32_t m_firRate
Rate of FIR filter (Rx: out, Tx: in) - this is the host/device communication sample rate...
DevicePlutoSDRBox * getBox()
void getDeviceEngineStateStr(QString &state)
uint32_t m_hb2Rate
Rate of the HB2 filter (Rx: out, Tx: in) - this is the HB1 working sample rate.
const QString & getSamplingDeviceSerial() const
uint32_t m_hb1Rate
Rate of the HB1 filter (Rx: out, Tx: in) - this is the FIR working sample rate.
uint32_t m_bbRateHz
Baseband PLL rate (Hz) - used internally.
SWGPlutoSdrInputSettings * getPlutoSdrInputSettings()
void configureCorrections(bool dcOffsetCorrection, bool iqImbalanceCorrection, int streamIndex=0)
Configure current device engine DSP corrections (Rx)
void setPlutoSdrInputSettings(SWGPlutoSdrInputSettings *pluto_sdr_input_settings)
void setDirection(qint32 direction)
uint32_t m_addaConnvRate
A/D or D/A converter rat - this is the HB3 working sample rate.
T max(const T &x, const T &y)
virtual void startWork()=0
void setDeviceHwType(QString *device_hw_type)
void setPlutoSdrInputReport(SWGPlutoSdrInputReport *pluto_sdr_input_report)
void set_params(DeviceType devType, const std::vector< std::string > ¶ms)
uint64_t getDevSampleRate() const
T min(const T &x, const T &y)
unsigned __int64 uint64_t