| 
									
										
										
										
											2019-08-01 02:16:56 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015-2019 Edouard Griffiths, F4EXB.                             //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // Swagger server adapter interface                                              //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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                  //
 | 
					
						
							|  |  |  | // (at your option) any later version.                                           //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "settings/preset.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-08-09 10:33:04 +02:00
										 |  |  | #include <QDebug>
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | Preset::Preset() | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	resetToDefaults(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-09 18:45:10 +02:00
										 |  |  | Preset::Preset(const Preset& other) : | 
					
						
							|  |  |  | 	m_group(other.m_group), | 
					
						
							|  |  |  | 	m_description(other.m_description), | 
					
						
							|  |  |  | 	m_centerFrequency(other.m_centerFrequency), | 
					
						
							|  |  |  | 	m_spectrumConfig(other.m_spectrumConfig), | 
					
						
							|  |  |  | 	m_dcOffsetCorrection(other.m_dcOffsetCorrection), | 
					
						
							|  |  |  | 	m_iqImbalanceCorrection(other.m_iqImbalanceCorrection), | 
					
						
							|  |  |  | 	m_channelConfigs(other.m_channelConfigs), | 
					
						
							|  |  |  | 	m_deviceConfigs(other.m_deviceConfigs), | 
					
						
							|  |  |  | 	m_layout(other.m_layout) | 
					
						
							|  |  |  | {} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | void Preset::resetToDefaults() | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2020-04-28 05:47:49 +02:00
										 |  |  |     m_presetType = PresetSource; // Rx
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	m_group = "default"; | 
					
						
							|  |  |  | 	m_description = "no name"; | 
					
						
							|  |  |  | 	m_centerFrequency = 0; | 
					
						
							|  |  |  | 	m_spectrumConfig.clear(); | 
					
						
							|  |  |  | 	m_layout.clear(); | 
					
						
							|  |  |  | 	m_channelConfigs.clear(); | 
					
						
							| 
									
										
										
										
											2018-02-22 03:04:42 +01:00
										 |  |  | 	m_dcOffsetCorrection = false; | 
					
						
							|  |  |  | 	m_iqImbalanceCorrection = false; | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | QByteArray Preset::serialize() const | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2017-09-05 08:23:05 +02:00
										 |  |  | //	qDebug("Preset::serialize: m_group: %s mode: %s m_description: %s m_centerFrequency: %llu",
 | 
					
						
							|  |  |  | //			qPrintable(m_group),
 | 
					
						
							|  |  |  | //			m_sourcePreset ? "Rx" : "Tx",
 | 
					
						
							|  |  |  | //			qPrintable(m_description),
 | 
					
						
							|  |  |  | //			m_centerFrequency);
 | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	SimpleSerializer s(1); | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	s.writeString(1, m_group); | 
					
						
							|  |  |  | 	s.writeString(2, m_description); | 
					
						
							|  |  |  | 	s.writeU64(3, m_centerFrequency); | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 	s.writeBlob(4, m_layout); | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 	s.writeBlob(5, m_spectrumConfig); | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |     s.writeBool(6, m_presetType == PresetSource); | 
					
						
							|  |  |  | 	s.writeS32(7, (int) m_presetType); | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	s.writeS32(20, m_deviceConfigs.size()); | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	for (int i = 0; i < m_deviceConfigs.size(); i++) | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		s.writeString(24 + i*4, m_deviceConfigs[i].m_deviceId); | 
					
						
							|  |  |  | 		s.writeString(25 + i*4, m_deviceConfigs[i].m_deviceSerial); | 
					
						
							|  |  |  | 		s.writeS32(26 + i*4, m_deviceConfigs[i].m_deviceSequence); | 
					
						
							|  |  |  | 		s.writeBlob(27 + i*4, m_deviceConfigs[i].m_config); | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-05 08:23:05 +02:00
										 |  |  | //		qDebug("Preset::serialize:  source: id: %s, ser: %s, seq: %d",
 | 
					
						
							|  |  |  | //			qPrintable(m_deviceConfigs[i].m_deviceId),
 | 
					
						
							|  |  |  | //			qPrintable(m_deviceConfigs[i].m_deviceSerial),
 | 
					
						
							|  |  |  | //			m_deviceConfigs[i].m_deviceSequence);
 | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 		if (i >= (200-23)/4) // full!
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2017-09-05 08:23:05 +02:00
										 |  |  | 		    qWarning("Preset::serialize: too many sources"); | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-06-07 03:30:28 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 	s.writeS32(200, m_channelConfigs.size()); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for(int i = 0; i < m_channelConfigs.size(); i++) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2017-09-05 08:23:05 +02:00
										 |  |  | //		qDebug("Preset::serialize:  channel: id: %s", qPrintable(m_channelConfigs[i].m_channel));
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-11-23 01:19:32 +01:00
										 |  |  | 		s.writeString(201 + i * 2, m_channelConfigs[i].m_channelIdURI); | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 		s.writeBlob(202 + i * 2, m_channelConfigs[i].m_config); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 	return s.final(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool Preset::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SimpleDeserializer d(data); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 	if (!d.isValid()) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 	if (d.getVersion() == 1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  |         bool tmpBool; | 
					
						
							|  |  |  |         int tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		d.readString(1, &m_group, "default"); | 
					
						
							|  |  |  | 		d.readString(2, &m_description, "no name"); | 
					
						
							|  |  |  | 		d.readU64(3, &m_centerFrequency, 0); | 
					
						
							| 
									
										
										
										
											2015-09-30 03:46:46 +02:00
										 |  |  | 		d.readBlob(4, &m_layout); | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 		d.readBlob(5, &m_spectrumConfig); | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  | 		d.readBool(6, &tmpBool, true); | 
					
						
							|  |  |  |         d.readS32(7, &tmp, PresetSource); | 
					
						
							|  |  |  |         m_presetType = tmp < (int) PresetSource ? PresetSource : tmp > (int) PresetMIMO ? PresetMIMO : (PresetType) tmp; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (m_presetType != PresetMIMO) { | 
					
						
							|  |  |  |             m_presetType = tmpBool ? PresetSource : PresetSink; | 
					
						
							|  |  |  |         } | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 22:20:28 +02:00
										 |  |  | //		qDebug("Preset::deserialize: m_group: %s mode: %s m_description: %s m_centerFrequency: %llu",
 | 
					
						
							|  |  |  | //				qPrintable(m_group),
 | 
					
						
							|  |  |  | //				m_sourcePreset ? "Rx" : "Tx",
 | 
					
						
							|  |  |  | //				qPrintable(m_description),
 | 
					
						
							|  |  |  | //				m_centerFrequency);
 | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		qint32 sourcesCount = 0; | 
					
						
							|  |  |  | 		d.readS32(20, &sourcesCount, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 		if (sourcesCount >= (200-23)/4) // limit was hit!
 | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 			sourcesCount = ((200-23)/4) - 1; | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		m_deviceConfigs.clear(); | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < sourcesCount; i++) | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			QString sourceId, sourceSerial; | 
					
						
							|  |  |  | 			int sourceSequence; | 
					
						
							|  |  |  | 			QByteArray sourceConfig; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 			d.readString(24 + i*4, &sourceId, ""); | 
					
						
							|  |  |  | 			d.readString(25 + i*4, &sourceSerial, ""); | 
					
						
							|  |  |  | 			d.readS32(26 + i*4, &sourceSequence, 0); | 
					
						
							|  |  |  | 			d.readBlob(27 + i*4, &sourceConfig); | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 			if (!sourceId.isEmpty()) | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2017-09-04 22:20:28 +02:00
										 |  |  | //				qDebug("Preset::deserialize:  source: id: %s, ser: %s, seq: %d",
 | 
					
						
							|  |  |  | //					qPrintable(sourceId),
 | 
					
						
							|  |  |  | //					qPrintable(sourceSerial),
 | 
					
						
							|  |  |  | //					sourceSequence);
 | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 				m_deviceConfigs.append(DeviceConfig(sourceId, sourceSerial, sourceSequence, sourceConfig)); | 
					
						
							| 
									
										
										
										
											2015-10-02 02:22:56 +02:00
										 |  |  | 			} | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  |         qint32 channelCount; | 
					
						
							|  |  |  |         d.readS32(200, &channelCount, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		m_channelConfigs.clear(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 		for (int i = 0; i < channelCount; i++) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			QString channel; | 
					
						
							|  |  |  | 			QByteArray config; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			d.readString(201 + i * 2, &channel, "unknown-channel"); | 
					
						
							|  |  |  | 			d.readBlob(202 + i * 2, &config); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2017-09-04 22:20:28 +02:00
										 |  |  | //			qDebug("Preset::deserialize:  channel: id: %s", qPrintable(channel));
 | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 			m_channelConfigs.append(ChannelConfig(channel, config)); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2015-10-09 01:50:09 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							| 
									
										
										
										
											2015-10-01 16:57:33 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2014-05-18 16:52:39 +01:00
										 |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | void Preset::addOrUpdateDeviceConfig(const QString& sourceId, | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		const QString& sourceSerial, | 
					
						
							|  |  |  | 		int sourceSequence, | 
					
						
							|  |  |  | 		const QByteArray& config) | 
					
						
							|  |  |  | { | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	DeviceeConfigs::iterator it = m_deviceConfigs.begin(); | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	for (; it != m_deviceConfigs.end(); ++it) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		if (it->m_deviceId == sourceId) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		{ | 
					
						
							|  |  |  | 			if (sourceSerial.isNull() || sourceSerial.isEmpty()) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 				if (it->m_deviceSequence == sourceSequence) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 				if (it->m_deviceSerial == sourceSerial) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	if (it == m_deviceConfigs.end()) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		m_deviceConfigs.append(DeviceConfig(sourceId, sourceSerial, sourceSequence, config)); | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		it->m_config = config; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-08-10 05:16:25 +02:00
										 |  |  | const QByteArray* Preset::findDeviceConfig( | 
					
						
							|  |  |  |         const QString& deviceId, | 
					
						
							|  |  |  |         const QString& deviceSerial, | 
					
						
							|  |  |  |         int deviceSequence) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     DeviceeConfigs::const_iterator it = m_deviceConfigs.begin(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     for (; it != m_deviceConfigs.end(); ++it) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2020-11-14 11:13:32 +01:00
										 |  |  |         if ((it->m_deviceId == deviceId) && (it->m_deviceSerial == deviceSerial) && (it->m_deviceSequence == deviceSequence)) { | 
					
						
							| 
									
										
										
										
											2019-08-10 05:16:25 +02:00
										 |  |  |             return &it->m_config; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     return nullptr; | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const QByteArray* Preset::findBestDeviceConfig( | 
					
						
							|  |  |  |         const QString& sourceId, | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		const QString& sourceSerial, | 
					
						
							| 
									
										
										
										
											2015-10-02 04:04:38 +02:00
										 |  |  | 		int sourceSequence) const | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2019-01-13 22:09:45 +01:00
										 |  |  | 	// Special case for SoapySDR based on serial (driver name)
 | 
					
						
							|  |  |  | 	if (sourceId == "sdrangel.samplesource.soapysdrinput") { | 
					
						
							|  |  |  | 		return findBestDeviceConfigSoapy(sourceId, sourceSerial); | 
					
						
							|  |  |  | 	} else if (sourceId == "sdrangel.samplesource.soapysdroutput") { | 
					
						
							|  |  |  | 		return findBestDeviceConfigSoapy(sourceId, sourceSerial); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	DeviceeConfigs::const_iterator it = m_deviceConfigs.begin(); | 
					
						
							|  |  |  | 	DeviceeConfigs::const_iterator itFirstOfKind = m_deviceConfigs.end(); | 
					
						
							|  |  |  | 	DeviceeConfigs::const_iterator itMatchSequence = m_deviceConfigs.end(); | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	for (; it != m_deviceConfigs.end(); ++it) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		if (it->m_deviceId == sourceId) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 			if (itFirstOfKind == m_deviceConfigs.end()) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 			{ | 
					
						
							|  |  |  | 				itFirstOfKind = it; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (sourceSerial.isNull() || sourceSerial.isEmpty()) | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 				if (it->m_deviceSequence == sourceSequence) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else | 
					
						
							|  |  |  | 			{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 				if (it->m_deviceSerial == sourceSerial) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 				else if(it->m_deviceSequence == sourceSequence) | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 				{ | 
					
						
							|  |  |  | 					itMatchSequence = it; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 	if (it == m_deviceConfigs.end()) // no exact match
 | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		if (itMatchSequence != m_deviceConfigs.end()) // match sequence ?
 | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  | 			qDebug("Preset::findBestDeviceConfig: sequence matched: id: %s ser: %s seq: %d", | 
					
						
							| 
									
										
										
										
											2019-01-13 22:09:45 +01:00
										 |  |  | 				qPrintable(itMatchSequence->m_deviceId), qPrintable(itMatchSequence->m_deviceSerial), itMatchSequence->m_deviceSequence); | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 			return &(itMatchSequence->m_config); | 
					
						
							|  |  |  | 		} | 
					
						
							| 
									
										
										
										
											2016-10-19 00:07:42 +02:00
										 |  |  | 		else if (itFirstOfKind != m_deviceConfigs.end()) // match source type ?
 | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  | 			qDebug("Preset::findBestDeviceConfig: first of kind matched: id: %s ser: %s seq: %d", | 
					
						
							| 
									
										
										
										
											2019-01-13 22:09:45 +01:00
										 |  |  | 				qPrintable(itFirstOfKind->m_deviceId), qPrintable(itFirstOfKind->m_deviceSerial), itFirstOfKind->m_deviceSequence); | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 			return &(itFirstOfKind->m_config); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else // definitely not found !
 | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  | 			qDebug("Preset::findBestDeviceConfig: no match"); | 
					
						
							|  |  |  | 			return nullptr; | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else // exact match
 | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  | 		qDebug("Preset::findBestDeviceConfig: serial matched (exact): id: %s ser: %s", | 
					
						
							| 
									
										
										
										
											2019-01-13 22:09:45 +01:00
										 |  |  | 			qPrintable(it->m_deviceId), qPrintable(it->m_deviceSerial)); | 
					
						
							|  |  |  | 		return &(it->m_config); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | const QByteArray* Preset::findBestDeviceConfigSoapy(const QString& sourceId, const QString& sourceSerial) const | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	QStringList sourceSerialPieces = sourceSerial.split("-"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (sourceSerialPieces.size() == 0) { | 
					
						
							|  |  |  | 		return 0; // unable to process
 | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	DeviceeConfigs::const_iterator it = m_deviceConfigs.begin(); | 
					
						
							|  |  |  | 	DeviceeConfigs::const_iterator itFirstOfKind = m_deviceConfigs.end(); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	for (; it != m_deviceConfigs.end(); ++it) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (it->m_deviceId != sourceId) // skip non matching device
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			continue; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else if (it->m_deviceSerial == sourceSerial) // exact match
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			break; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else // try to find best match on driver id (first part of serial)
 | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			QStringList serialPieces = it->m_deviceSerial.split("-"); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 			if (serialPieces.size() == 0) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				continue; | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 			else if (sourceSerialPieces[0] == serialPieces[0]) | 
					
						
							|  |  |  | 			{ | 
					
						
							|  |  |  | 				if (itFirstOfKind == m_deviceConfigs.end()) | 
					
						
							|  |  |  | 				{ | 
					
						
							|  |  |  | 					itFirstOfKind = it; | 
					
						
							|  |  |  | 					break; | 
					
						
							|  |  |  | 				} | 
					
						
							|  |  |  | 			} | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (it == m_deviceConfigs.end()) // no exact match
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		if (itFirstOfKind == m_deviceConfigs.end()) | 
					
						
							|  |  |  | 		{ | 
					
						
							|  |  |  | 			qDebug("Preset::findBestDeviceConfigSoapy: no match"); | 
					
						
							|  |  |  | 			return 0; | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 		else | 
					
						
							|  |  |  | 		{ | 
					
						
							| 
									
										
										
										
											2019-09-13 13:40:31 +02:00
										 |  |  | 			qDebug("Preset::findBestDeviceConfigSoapy: first of kind matched: id: %s ser: %s seq: %d", | 
					
						
							| 
									
										
										
										
											2019-01-13 22:09:45 +01:00
										 |  |  | 				qPrintable(itFirstOfKind->m_deviceId), qPrintable(itFirstOfKind->m_deviceSerial), itFirstOfKind->m_deviceSequence); | 
					
						
							|  |  |  | 			return &(itFirstOfKind->m_config); | 
					
						
							|  |  |  | 		} | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else // exact match
 | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		qDebug("Preset::findBestDeviceConfigSoapy: serial matched (exact): id: %s ser: %s seq: %d", | 
					
						
							|  |  |  | 			qPrintable(it->m_deviceId), qPrintable(it->m_deviceSerial), it->m_deviceSequence); | 
					
						
							| 
									
										
										
										
											2015-10-01 08:54:56 +02:00
										 |  |  | 		return &(it->m_config); | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | } |