| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2017 Edouard Griffiths, F4EXB                                   //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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-04-11 18:13:40 +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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QDebug>
 | 
					
						
							|  |  |  | #include "devicelimesdrparam.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool DeviceLimeSDRParams::open(lms_info_str_t deviceStr) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2018-11-29 23:37:34 +01:00
										 |  |  |     getHardwareType((const char *) deviceStr); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     qDebug("DeviceLimeSDRParams::open: serial: %s type: %d", (const char *) deviceStr, (int) m_type); | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (LMS_Open(&m_dev, deviceStr, 0) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot open device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_Init(m_dev) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot init device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     int n; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((n = LMS_GetNumChannels(m_dev, LMS_CH_RX)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the number of Rx channels for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_nbRxChannels = n; | 
					
						
							| 
									
										
										
										
											2017-04-11 22:26:42 +02:00
										 |  |  |         qDebug() << "DeviceLimeSDRParams::open: " << n << " Rx channels for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if ((n = LMS_GetNumChannels(m_dev, LMS_CH_TX)) < 0) | 
					
						
							|  |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the number of Tx channels for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         m_nbTxChannels = n; | 
					
						
							| 
									
										
										
										
											2017-04-11 22:26:42 +02:00
										 |  |  |         qDebug() << "DeviceLimeSDRParams::open: " << n << " Tx channels for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_GetLPFBWRange(m_dev, LMS_CH_RX, &m_lpfRangeRx) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the Rx LPF range for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_GetLPFBWRange(m_dev, LMS_CH_TX, &m_lpfRangeTx) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the Tx LPF range for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_GetLOFrequencyRange(m_dev, LMS_CH_RX, &m_loRangeRx) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-04-11 22:26:42 +02:00
										 |  |  |         qDebug() << "DeviceLimeSDRParams::open: cannot get the Rx LO range for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_GetLOFrequencyRange(m_dev, LMS_CH_TX, &m_loRangeTx) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the Tx LO range for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_GetSampleRateRange(m_dev, LMS_CH_RX, &m_srRangeRx) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the Rx sample rate range for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-18 00:50:03 +02:00
										 |  |  |     if (LMS_GetSampleRateRange(m_dev, LMS_CH_TX, &m_srRangeTx) < 0) | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |     { | 
					
						
							| 
									
										
										
										
											2017-11-12 03:12:01 +01:00
										 |  |  |         qCritical() << "DeviceLimeSDRParams::open: cannot get the Tx sample rate range for device " << deviceStr; | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return true; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-04-13 18:18:15 +02:00
										 |  |  | void DeviceLimeSDRParams::close() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     if (m_dev) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         LMS_Close(m_dev); | 
					
						
							|  |  |  |         m_dev = 0; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2017-04-11 18:13:40 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-11-29 23:37:34 +01:00
										 |  |  | void DeviceLimeSDRParams::getHardwareType(const char *device_str) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     QString deviceStr(device_str); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if (deviceStr.contains(QString("LimeSDR Mini"))) { | 
					
						
							|  |  |  |         m_type = LimeMini; | 
					
						
							|  |  |  |     } else if (deviceStr.contains(QString("LimeSDR-USB"))) { | 
					
						
							|  |  |  |         m_type = LimeUSB; | 
					
						
							|  |  |  |     } else if (deviceStr.contains(QString("media=SPI"))) { | 
					
						
							|  |  |  |         m_type = LimeSPI; | 
					
						
							|  |  |  |     } else { | 
					
						
							|  |  |  |         m_type = LimeUndefined; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } |