| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 05:24:06 +01:00
										 |  |  | // Copyright (C) 2017-2019, 2021 Edouard Griffiths, F4EXB <f4exb06@gmail.com>    //
 | 
					
						
							|  |  |  | // Copyright (C) 2019 Robin Getz <robin.getz@analog.com>                         //
 | 
					
						
							|  |  |  | // Copyright (C) 2020 Felix Schneider <felix@fx-schneider.de>                    //
 | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is free software; you can redistribute it and/or modify          //
 | 
					
						
							|  |  |  | // it under the terms of the GNU General Public License as published by          //
 | 
					
						
							|  |  |  | // the Free Software Foundation as version 3 of the License, or                  //
 | 
					
						
							| 
									
										
										
										
											2019-04-11 06:39:30 +02:00
										 |  |  | // (at your option) any later version.                                           //
 | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // This program is distributed in the hope that it will be useful,               //
 | 
					
						
							|  |  |  | // but WITHOUT ANY WARRANTY; without even the implied warranty of                //
 | 
					
						
							|  |  |  | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the                  //
 | 
					
						
							|  |  |  | // GNU General Public License V3 for more details.                               //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // You should have received a copy of the GNU General Public License             //
 | 
					
						
							|  |  |  | // along with this program. If not, see <http://www.gnu.org/licenses/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef DEVICES_PLUTOSDR_DEVICEPLUTOSDRBOX_H_
 | 
					
						
							|  |  |  | #define DEVICES_PLUTOSDR_DEVICEPLUTOSDRBOX_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 18:41:55 +02:00
										 |  |  | #include <sstream>
 | 
					
						
							| 
									
										
										
										
											2017-09-06 06:15:38 +02:00
										 |  |  | #include <stdint.h>
 | 
					
						
							|  |  |  | #include <sys/types.h>
 | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-25 22:28:40 +02:00
										 |  |  | #include <QList>
 | 
					
						
							|  |  |  | #include <QString>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "deviceplutosdrscan.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-20 13:49:21 +01:00
										 |  |  | #include "export.h"
 | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-28 18:30:11 +01:00
										 |  |  | #if defined(_MSC_VER)
 | 
					
						
							|  |  |  | #include <BaseTsd.h>
 | 
					
						
							|  |  |  | typedef SSIZE_T ssize_t; | 
					
						
							|  |  |  | #endif
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-04-25 22:28:40 +02:00
										 |  |  | struct iio_channel; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-03 20:23:38 +01:00
										 |  |  | class DEVICES_API DevicePlutoSDRBox | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | { | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     typedef enum | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         DEVICE_PHY, | 
					
						
							|  |  |  |         DEVICE_RX, | 
					
						
							|  |  |  |         DEVICE_TX | 
					
						
							|  |  |  |     } DeviceType; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-07 08:49:22 +02:00
										 |  |  |     typedef enum | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         USE_RX, | 
					
						
							|  |  |  |         USE_TX | 
					
						
							|  |  |  |     } DeviceUse; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  |     struct Sample { | 
					
						
							|  |  |  |         int16_t i; | 
					
						
							|  |  |  |         int16_t q; | 
					
						
							|  |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-06 18:48:58 +02:00
										 |  |  |     struct SampleRates { | 
					
						
							| 
									
										
										
										
											2017-09-10 10:16:23 +02:00
										 |  |  |         uint32_t m_bbRateHz;      //!< Baseband PLL rate (Hz) - used internally
 | 
					
						
							|  |  |  |         uint32_t m_addaConnvRate; //!< A/D or D/A converter rat - this is the HB3 working sample rate
 | 
					
						
							|  |  |  |         uint32_t m_hb3Rate;       //!< Rate of the HB3/(DEC3 or INT3) filter (Rx: out, Tx: in) - this is the HB2 working sample rate
 | 
					
						
							|  |  |  |         uint32_t m_hb2Rate;       //!< Rate of the HB2 filter (Rx: out, Tx: in) - this is the HB1 working sample rate
 | 
					
						
							|  |  |  |         uint32_t m_hb1Rate;       //!< Rate of the HB1 filter (Rx: out, Tx: in) - this is the FIR working sample rate
 | 
					
						
							|  |  |  |         uint32_t m_firRate;       //!< Rate of FIR filter (Rx: out, Tx: in) - this is the host/device communication sample rate
 | 
					
						
							| 
									
										
										
										
											2017-09-06 18:48:58 +02:00
										 |  |  |     }; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-09 03:09:17 +02:00
										 |  |  |     uint64_t m_devSampleRate;      //!< Host interface sample rate
 | 
					
						
							|  |  |  |     int32_t  m_LOppmTenths;        //!< XO correction
 | 
					
						
							|  |  |  |     bool     m_lpfFIREnable;       //!< enable digital lowpass FIR filter
 | 
					
						
							|  |  |  |     float    m_lpfFIRBW;           //!< digital lowpass FIR filter bandwidth (Hz)
 | 
					
						
							|  |  |  |     uint32_t m_lpfFIRlog2Decim;    //!< digital lowpass FIR filter log2 of decimation factor (0..2)
 | 
					
						
							| 
									
										
										
										
											2017-09-11 23:51:58 +02:00
										 |  |  |     int      m_lpfFIRRxGain;       //!< digital lowpass FIR filter gain Rx side (dB)
 | 
					
						
							|  |  |  |     int      m_lpfFIRTxGain;       //!< digital lowpass FIR filter gain Tx side (dB)
 | 
					
						
							| 
									
										
										
										
											2017-09-09 03:09:17 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  |     DevicePlutoSDRBox(const std::string& uri); | 
					
						
							|  |  |  |     ~DevicePlutoSDRBox(); | 
					
						
							|  |  |  |     bool isValid() const { return m_valid; } | 
					
						
							| 
									
										
										
										
											2017-09-23 03:42:58 +02:00
										 |  |  |     static bool probeURI(const std::string& uri); | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     void set_params(DeviceType devType, const std::vector<std::string> ¶ms); | 
					
						
							| 
									
										
										
										
											2017-09-05 15:06:40 +02:00
										 |  |  |     bool get_param(DeviceType devType, const std::string ¶m, std::string &value); | 
					
						
							| 
									
										
										
										
											2021-05-01 09:50:51 +02:00
										 |  |  |     bool openRx();        //!< Open first Rx (Rx0)
 | 
					
						
							|  |  |  |     bool openTx();        //!< Open first Tx (Tx0)
 | 
					
						
							|  |  |  |     bool openSecondRx();  //!< Open second Rx (Rx1)
 | 
					
						
							|  |  |  |     bool openSecondTx();  //!< Open second Tx (Tx1)
 | 
					
						
							|  |  |  |     void closeRx();       //!< Close first Rx (Rx0)
 | 
					
						
							|  |  |  |     void closeTx();       //!< Close first Tx (Tx0)
 | 
					
						
							|  |  |  |     void closeSecondRx(); //!< Close second Rx (Rx1)
 | 
					
						
							|  |  |  |     void closeSecondTx(); //!< Close second Tx (Tx1)
 | 
					
						
							| 
									
										
										
										
											2021-04-25 22:28:40 +02:00
										 |  |  |     int getNbRx() const { return m_rxChannels.size() / 2; } | 
					
						
							|  |  |  |     int getNbTx() const { return m_txChannels.size() / 2; } | 
					
						
							| 
									
										
										
										
											2021-05-04 16:32:58 +02:00
										 |  |  |     int getRxSampleBytes() const { return m_rxSampleBytes; } | 
					
						
							|  |  |  |     int getTxSampleBytes() const { return m_txSampleBytes; } | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  |     struct iio_buffer *createRxBuffer(unsigned int size, bool cyclic); | 
					
						
							|  |  |  |     struct iio_buffer *createTxBuffer(unsigned int size, bool cyclic); | 
					
						
							|  |  |  |     void deleteRxBuffer(); | 
					
						
							|  |  |  |     void deleteTxBuffer(); | 
					
						
							|  |  |  |     ssize_t getRxSampleSize(); | 
					
						
							|  |  |  |     ssize_t getTxSampleSize(); | 
					
						
							|  |  |  |     ssize_t rxBufferRefill(); | 
					
						
							|  |  |  |     ssize_t txBufferPush(); | 
					
						
							|  |  |  |     std::ptrdiff_t rxBufferStep(); | 
					
						
							|  |  |  |     char* rxBufferEnd(); | 
					
						
							|  |  |  |     char* rxBufferFirst(); | 
					
						
							|  |  |  |     std::ptrdiff_t txBufferStep(); | 
					
						
							|  |  |  |     char* txBufferEnd(); | 
					
						
							|  |  |  |     char* txBufferFirst(); | 
					
						
							| 
									
										
										
										
											2017-10-29 03:01:44 +01:00
										 |  |  |     void txChannelConvert(int16_t *dst, int16_t *src); | 
					
						
							| 
									
										
										
										
											2021-05-01 09:50:51 +02:00
										 |  |  |     void txChannelConvert(int chanIndex, int16_t *dst, int16_t *src); | 
					
						
							| 
									
										
										
										
											2017-09-06 18:48:58 +02:00
										 |  |  |     bool getRxSampleRates(SampleRates& sampleRates); | 
					
						
							|  |  |  |     bool getTxSampleRates(SampleRates& sampleRates); | 
					
						
							| 
									
										
										
										
											2017-09-09 03:09:17 +02:00
										 |  |  |     void setSampleRate(uint32_t sampleRate); | 
					
						
							| 
									
										
										
										
											2017-09-11 23:51:58 +02:00
										 |  |  |     void setFIR(uint32_t sampleRate, uint32_t intdec, DeviceUse use, uint32_t bw, int gain); | 
					
						
							| 
									
										
										
										
											2017-09-09 03:09:17 +02:00
										 |  |  |     void setFIREnable(bool enable); | 
					
						
							|  |  |  |     void setLOPPMTenths(int ppmTenths); | 
					
						
							| 
									
										
										
										
											2017-10-09 02:18:04 +02:00
										 |  |  |     bool getRxGain(int& gaindB, unsigned int chan); | 
					
						
							| 
									
										
										
										
											2017-09-19 08:33:26 +02:00
										 |  |  |     bool getRxRSSI(std::string& rssiStr, unsigned int chan); | 
					
						
							|  |  |  |     bool getTxRSSI(std::string& rssiStr, unsigned int chan); | 
					
						
							| 
									
										
										
										
											2019-01-04 11:23:54 +01:00
										 |  |  |     void getRxLORange(uint64_t& minLimit, uint64_t& maxLimit); | 
					
						
							|  |  |  |     void getTxLORange(uint64_t& minLimit, uint64_t& maxLimit); | 
					
						
							| 
									
										
										
										
											2019-02-01 16:42:08 -05:00
										 |  |  |     void getbbLPRxRange(uint32_t& minLimit, uint32_t& maxLimit); | 
					
						
							|  |  |  |     void getbbLPTxRange(uint32_t& minLimit, uint32_t& maxLimit); | 
					
						
							| 
									
										
										
										
											2017-09-09 03:09:17 +02:00
										 |  |  |     bool fetchTemp(); | 
					
						
							|  |  |  |     float getTemp() const { return m_temp; } | 
					
						
							|  |  |  |     bool getRateGovernors(std::string& rateGovernors); | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     struct iio_context *m_ctx; | 
					
						
							|  |  |  |     struct iio_device  *m_devPhy; | 
					
						
							|  |  |  |     struct iio_device  *m_devRx; | 
					
						
							|  |  |  |     struct iio_device  *m_devTx; | 
					
						
							|  |  |  |     struct iio_buffer  *m_rxBuf; | 
					
						
							|  |  |  |     struct iio_buffer  *m_txBuf; | 
					
						
							|  |  |  |     bool m_valid; | 
					
						
							| 
									
										
										
										
											2017-09-07 23:27:24 +02:00
										 |  |  |     int64_t m_xoInitial; | 
					
						
							| 
									
										
										
										
											2017-09-09 03:09:17 +02:00
										 |  |  |     float m_temp; | 
					
						
							| 
									
										
										
										
											2021-05-04 16:32:58 +02:00
										 |  |  |     int m_rxSampleBytes; //!< size in bytes of a Rx I or Q sample. Rx must be opened.
 | 
					
						
							|  |  |  |     int m_txSampleBytes; //!< size in bytes of a Tx I or Q sample. Tx must be opened.
 | 
					
						
							| 
									
										
										
										
											2021-04-25 22:28:40 +02:00
										 |  |  |     QList<QString> m_rxChannelIds; | 
					
						
							|  |  |  |     QList<iio_channel*> m_rxChannels; | 
					
						
							|  |  |  |     QList<QString> m_txChannelIds; | 
					
						
							|  |  |  |     QList<iio_channel*> m_txChannels; | 
					
						
							| 
									
										
										
										
											2017-09-06 18:48:58 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     bool parseSampleRates(const std::string& rateStr, SampleRates& sampleRates); | 
					
						
							| 
									
										
										
										
											2017-09-07 22:24:09 +02:00
										 |  |  |     void setFilter(const std::string& filterConfigStr); | 
					
						
							| 
									
										
										
										
											2017-09-11 23:51:58 +02:00
										 |  |  |     void formatFIRHeader(std::ostringstream& str, uint32_t intdec); | 
					
						
							| 
									
										
										
										
											2017-09-07 18:41:55 +02:00
										 |  |  |     void formatFIRCoefficients(std::ostringstream& str, uint32_t nbTaps, double normalizedBW); | 
					
						
							| 
									
										
										
										
											2017-09-07 23:27:24 +02:00
										 |  |  |     void getXO(); | 
					
						
							| 
									
										
										
										
											2017-09-02 04:21:41 +02:00
										 |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif /* DEVICES_PLUTOSDR_DEVICEPLUTOSDRBOX_H_ */
 |