mirror of
				https://github.com/f4exb/sdrangel.git
				synced 2025-10-31 04:50:29 -04:00 
			
		
		
		
	PlutoSDR input: implemented input class interim state (2)
This commit is contained in:
		
							parent
							
								
									7b437e41ba
								
							
						
					
					
						commit
						5a05cf14bb
					
				| @ -20,6 +20,7 @@ | ||||
| #include <regex> | ||||
| #include <iio.h> | ||||
| #include <boost/lexical_cast.hpp> | ||||
| #include <QtGlobal> | ||||
| 
 | ||||
| #include "deviceplutosdrbox.h" | ||||
| 
 | ||||
| @ -77,7 +78,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, | ||||
| 
 | ||||
|         if (pos == std::string::npos) | ||||
|         { | ||||
|             std::cerr << "PlutoSDRDevice::set_params: Misformed line: " << *it << std::endl; | ||||
|             std::cerr << "DevicePlutoSDRBox::set_params: Misformed line: " << *it << std::endl; | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
| @ -88,7 +89,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, | ||||
| 
 | ||||
|         if (ret) | ||||
|         { | ||||
|             std::cerr << "PlutoSDRDevice::set_params: Parameter not recognized: " << key << std::endl; | ||||
|             std::cerr << "DevicePlutoSDRBox::set_params: Parameter not recognized: " << key << std::endl; | ||||
|             continue; | ||||
|         } | ||||
| 
 | ||||
| @ -102,7 +103,7 @@ void DevicePlutoSDRBox::set_params(DeviceType devType, | ||||
| 
 | ||||
|         if (ret < 0) | ||||
|         { | ||||
|             std::cerr << "PlutoSDRDevice::set_params: Unable to write attribute " << key <<  ": " << ret << std::endl; | ||||
|             std::cerr << "DevicePlutoSDRBox::set_params: Unable to write attribute " << key <<  ": " << ret << std::endl; | ||||
|         } | ||||
|     } | ||||
| } | ||||
| @ -136,7 +137,7 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, | ||||
| 
 | ||||
|     if (ret) | ||||
|     { | ||||
|         std::cerr << "PlutoSDRDevice::get_param: Parameter not recognized: " << param << std::endl; | ||||
|         std::cerr << "DevicePlutoSDRBox::get_param: Parameter not recognized: " << param << std::endl; | ||||
|         return false; | ||||
|     } | ||||
| 
 | ||||
| @ -150,7 +151,7 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, | ||||
| 
 | ||||
|     if (nchars < 0) | ||||
|     { | ||||
|         std::cerr << "PlutoSDRDevice::get_param: Unable to read attribute " << param <<  ": " << nchars << std::endl; | ||||
|         std::cerr << "DevicePlutoSDRBox::get_param: Unable to read attribute " << param <<  ": " << nchars << std::endl; | ||||
|         return false; | ||||
|     } | ||||
|     else | ||||
| @ -160,6 +161,18 @@ bool DevicePlutoSDRBox::get_param(DeviceType devType, const std::string ¶m, | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| void DevicePlutoSDRBox::set_filter(const std::string &filterConfigStr) | ||||
| { | ||||
|     int ret; | ||||
| 
 | ||||
|     ret = iio_device_attr_write_raw(m_devPhy, "filter_fir_config", filterConfigStr.c_str(), filterConfigStr.size()); | ||||
| 
 | ||||
|     if (ret < 0) | ||||
|     { | ||||
|         std::cerr << "DevicePlutoSDRBox::set_filter: Unable to set: " <<  filterConfigStr <<  ": " << ret << std::endl; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool DevicePlutoSDRBox::openRx() | ||||
| { | ||||
|     if (!m_chnRx0) { | ||||
| @ -170,7 +183,7 @@ bool DevicePlutoSDRBox::openRx() | ||||
|         iio_channel_enable(m_chnRx0); | ||||
|         return true; | ||||
|     } else { | ||||
|         std::cerr << "PlutoSDRDevice::openRx: failed" << std::endl; | ||||
|         std::cerr << "DevicePlutoSDRBox::openRx: failed" << std::endl; | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
| @ -185,7 +198,7 @@ bool DevicePlutoSDRBox::openTx() | ||||
|         iio_channel_enable(m_chnTx0); | ||||
|         return true; | ||||
|     } else { | ||||
|         std::cerr << "PlutoSDRDevice::openTx: failed" << std::endl; | ||||
|         std::cerr << "DevicePlutoSDRBox::openTx: failed" << std::endl; | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
| @ -328,6 +341,28 @@ char* DevicePlutoSDRBox::txBufferFirst() | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool DevicePlutoSDRBox::getRxSampleRates(SampleRates& sampleRates) | ||||
| { | ||||
|     std::string srStr; | ||||
| 
 | ||||
|     if (get_param(DEVICE_PHY, "rx_path_rates", srStr)) { | ||||
|         return parseSampleRates(srStr, sampleRates); | ||||
|     } else { | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool DevicePlutoSDRBox::getTxSampleRates(SampleRates& sampleRates) | ||||
| { | ||||
|     std::string srStr; | ||||
| 
 | ||||
|     if (get_param(DEVICE_PHY, "tx_path_rates", srStr)) { | ||||
|         return parseSampleRates(srStr, sampleRates); | ||||
|     } else { | ||||
|         return false; | ||||
|     } | ||||
| } | ||||
| 
 | ||||
| bool DevicePlutoSDRBox::parseSampleRates(const std::string& rateStr, SampleRates& sampleRates) | ||||
| { | ||||
|     // Rx: "BBPLL:983040000 ADC:245760000 R2:122880000 R1:61440000 RF:30720000 RXSAMP:30720000"
 | ||||
| @ -341,12 +376,12 @@ bool DevicePlutoSDRBox::parseSampleRates(const std::string& rateStr, SampleRates | ||||
|     { | ||||
|         try | ||||
|         { | ||||
|             sampleRates.m_bbRate = boost::lexical_cast<uint32_t>(desc_match[1]); | ||||
|             sampleRates.m_addaConnvRate = boost::lexical_cast<uint32_t>(desc_match[2]); | ||||
|             sampleRates.m_hb3Rate = boost::lexical_cast<uint32_t>(desc_match[3]); | ||||
|             sampleRates.m_hb2Rate = boost::lexical_cast<uint32_t>(desc_match[4]); | ||||
|             sampleRates.m_hb1Rate = boost::lexical_cast<uint32_t>(desc_match[5]); | ||||
|             sampleRates.m_firRate = boost::lexical_cast<uint32_t>(desc_match[6]); | ||||
|             sampleRates.m_bbRate = boost::lexical_cast<uint32_t>(desc_match[1]) + 1; | ||||
|             sampleRates.m_addaConnvRate = boost::lexical_cast<uint32_t>(desc_match[2]) + 1; | ||||
|             sampleRates.m_hb3Rate = boost::lexical_cast<uint32_t>(desc_match[3]) + 1; | ||||
|             sampleRates.m_hb2Rate = boost::lexical_cast<uint32_t>(desc_match[4]) + 1; | ||||
|             sampleRates.m_hb1Rate = boost::lexical_cast<uint32_t>(desc_match[5]) + 1; | ||||
|             sampleRates.m_firRate = boost::lexical_cast<uint32_t>(desc_match[6]) + 1; | ||||
|             return true; | ||||
|         } | ||||
|         catch (const boost::bad_lexical_cast &e) | ||||
|  | ||||
| @ -51,6 +51,7 @@ public: | ||||
| 
 | ||||
|     void set_params(DeviceType devType, const std::vector<std::string> ¶ms); | ||||
|     bool get_param(DeviceType devType, const std::string ¶m, std::string &value); | ||||
|     void set_filter(const std::string &filterConfigStr); | ||||
|     bool openRx(); | ||||
|     bool openTx(); | ||||
|     void closeRx(); | ||||
|  | ||||
| @ -254,9 +254,11 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo | ||||
|     //   - device to host sample rate is changed
 | ||||
|     //   - rate governor is changed
 | ||||
|     //   - FIR filter decimation is changed
 | ||||
|     //   - FIR filter is enabled or disabled
 | ||||
|     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || | ||||
|         (m_settings.m_rateGovernor != settings.m_rateGovernor) || | ||||
|         (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || force) | ||||
|         (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || | ||||
|         (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) | ||||
|     { | ||||
|         suspendAllOtherThreads = true; | ||||
|         suspendOwnThread = true; | ||||
| @ -300,8 +302,15 @@ bool PlutoSDRInput::applySettings(const PlutoSDRInputSettings& settings, bool fo | ||||
|     // Change affecting device baseband sample rate potentially affecting all buddies device/host sample rate
 | ||||
|     if ((m_settings.m_devSampleRate != settings.m_devSampleRate) || | ||||
|         (m_settings.m_rateGovernor != settings.m_rateGovernor) || | ||||
|         (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || force) | ||||
|         (m_settings.m_lpfFIRlog2Decim != settings.m_lpfFIRlog2Decim) || | ||||
|         (m_settings.m_lpfFIREnable != settings.m_lpfFIREnable) || force) | ||||
|     { | ||||
|         std::vector<std::string> params; | ||||
|         params.push_back(QString(tr("in_voltage_sampling_frequency=%1").arg(settings.m_devSampleRate)).toStdString()); | ||||
|         QString rateGovStr; | ||||
|         PlutoSDRInputSettings::translateGovernor(settings.m_rateGovernor, rateGovStr); | ||||
|         params.push_back(QString(tr("trx_rate_governor=%1").arg(rateGovStr)).toStdString()); | ||||
|         params.push_back(QString(tr("in_voltage_filter_fir_en=%1").arg(settings.m_lpfFIREnable ? 1 : 0)).toStdString()); | ||||
|         forwardChangeAllDSP = true; | ||||
|     } | ||||
| 
 | ||||
|  | ||||
| @ -44,7 +44,7 @@ public: | ||||
|         } | ||||
| 
 | ||||
|     private: | ||||
|         MsgConfigurePlutoSDR m_settings; | ||||
|         PlutoSDRInputSettings m_settings; | ||||
|         bool m_force; | ||||
| 
 | ||||
|         MsgConfigurePlutoSDR(const PlutoSDRInputSettings& settings, bool force) : | ||||
|  | ||||
| @ -129,3 +129,19 @@ bool PlutoSDRInputSettings::deserialize(const QByteArray& data) | ||||
| 		return false; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void PlutoSDRInputSettings::translateGovernor(RateGovernor gov, QString& s) | ||||
| { | ||||
|     switch(gov) | ||||
|     { | ||||
|     case RATEGOV_NORMAL: | ||||
|         s = "normal"; | ||||
|         break; | ||||
|     case RATEGOV_HIGHOSR: | ||||
|         s = "highest_osr"; | ||||
|         break; | ||||
|     default: | ||||
|         s = "highest_osr"; | ||||
|         break; | ||||
|     } | ||||
| } | ||||
|  | ||||
| @ -81,6 +81,7 @@ struct PlutoSDRInputSettings { | ||||
| 	void resetToDefaults(); | ||||
| 	QByteArray serialize() const; | ||||
| 	bool deserialize(const QByteArray& data); | ||||
| 	static void translateGovernor(RateGovernor gov, QString& s); | ||||
| }; | ||||
| 
 | ||||
| #endif /* _PLUTOSDR_PLUTOSDRINPUTSETTINGS_H_ */ | ||||
|  | ||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user