| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2015 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                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							|  |  |  | // 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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | #include <QtGlobal>
 | 
					
						
							|  |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "rtlsdrsettings.h"
 | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | RTLSDRSettings::RTLSDRSettings() | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	resetToDefaults(); | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | void RTLSDRSettings::resetToDefaults() | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	m_devSampleRate = 1024*1000; | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  | 	m_lowSampleRate = false; | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	m_centerFrequency = 435000*1000; | 
					
						
							|  |  |  | 	m_gain = 0; | 
					
						
							|  |  |  | 	m_loPpmCorrection = 0; | 
					
						
							|  |  |  | 	m_log2Decim = 4; | 
					
						
							| 
									
										
										
										
											2015-10-01 06:30:50 +02:00
										 |  |  | 	m_fcPos = FC_POS_CENTER; | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	m_dcBlock = false; | 
					
						
							|  |  |  | 	m_iqImbalance = false; | 
					
						
							| 
									
										
										
										
											2017-07-23 16:57:13 +02:00
										 |  |  | 	m_agc = false; | 
					
						
							| 
									
										
										
										
											2017-09-23 19:15:56 +02:00
										 |  |  | 	m_noModMode = false; | 
					
						
							|  |  |  |     m_transverterMode = false; | 
					
						
							|  |  |  | 	m_transverterDeltaFrequency = 0; | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | QByteArray RTLSDRSettings::serialize() const | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | { | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 	SimpleSerializer s(1); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	s.writeS32(2, m_gain); | 
					
						
							|  |  |  | 	s.writeS32(3, m_loPpmCorrection); | 
					
						
							|  |  |  | 	s.writeU32(4, m_log2Decim); | 
					
						
							|  |  |  | 	s.writeBool(5, m_dcBlock); | 
					
						
							|  |  |  | 	s.writeBool(6, m_iqImbalance); | 
					
						
							| 
									
										
										
										
											2015-10-01 06:30:50 +02:00
										 |  |  | 	s.writeS32(7, (int) m_fcPos); | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |     s.writeS32(8, m_devSampleRate); | 
					
						
							|  |  |  |     s.writeBool(9, m_lowSampleRate); | 
					
						
							| 
									
										
										
										
											2017-07-23 16:57:13 +02:00
										 |  |  |     s.writeBool(10, m_agc); | 
					
						
							| 
									
										
										
										
											2017-09-23 19:15:56 +02:00
										 |  |  |     s.writeBool(11, m_noModMode); | 
					
						
							|  |  |  |     s.writeBool(12, m_transverterMode); | 
					
						
							|  |  |  |     s.writeS64(13, m_transverterDeltaFrequency); | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 	return s.final(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | bool RTLSDRSettings::deserialize(const QByteArray& data) | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  | 	SimpleDeserializer d(data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (!d.isValid()) | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 	if (d.getVersion() == 1) | 
					
						
							|  |  |  | 	{ | 
					
						
							| 
									
										
										
										
											2015-10-01 06:30:50 +02:00
										 |  |  | 		int intval; | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 		d.readS32(2, &m_gain, 0); | 
					
						
							|  |  |  | 		d.readS32(3, &m_loPpmCorrection, 0); | 
					
						
							|  |  |  | 		d.readU32(4, &m_log2Decim, 4); | 
					
						
							|  |  |  | 		d.readBool(5, &m_dcBlock, false); | 
					
						
							|  |  |  | 		d.readBool(6, &m_iqImbalance, false); | 
					
						
							| 
									
										
										
										
											2015-10-01 06:30:50 +02:00
										 |  |  | 		d.readS32(7, &intval, 0); | 
					
						
							|  |  |  | 		m_fcPos = (fcPos_t) intval; | 
					
						
							| 
									
										
										
										
											2017-04-02 02:00:05 +02:00
										 |  |  |         d.readS32(8, &m_devSampleRate, 1024*1000); | 
					
						
							|  |  |  |         d.readBool(9, &m_lowSampleRate, false); | 
					
						
							| 
									
										
										
										
											2017-07-23 16:57:13 +02:00
										 |  |  |         d.readBool(10, &m_agc, false); | 
					
						
							| 
									
										
										
										
											2017-09-23 19:15:56 +02:00
										 |  |  |         d.readBool(11, &m_noModMode, false); | 
					
						
							|  |  |  |         d.readBool(12, &m_transverterMode, false); | 
					
						
							|  |  |  |         d.readS64(13, &m_transverterDeltaFrequency, 0); | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 		return true; | 
					
						
							|  |  |  | 	} | 
					
						
							|  |  |  | 	else | 
					
						
							|  |  |  | 	{ | 
					
						
							|  |  |  | 		resetToDefaults(); | 
					
						
							|  |  |  | 		return false; | 
					
						
							|  |  |  | 	} | 
					
						
							| 
									
										
										
										
											2015-08-28 03:20:00 +02:00
										 |  |  | } | 
					
						
							| 
									
										
										
										
											2015-10-01 04:39:00 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | 
 |