| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | // Copyright (C) 2018 Edouard Griffiths, F4EXB.                                  //
 | 
					
						
							|  |  |  | //                                                                               //
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | // Remote sink channel (Rx) UDP sender thread                                    //
 | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | //                                                                               //
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | // SDRangel can work as a detached SDR front end. With this plugin it can        //
 | 
					
						
							|  |  |  | // sends the I/Q samples stream to another SDRangel instance via UDP.            //
 | 
					
						
							|  |  |  | // It is controlled via a Web REST API.                                          //
 | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +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.                                           //
 | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | #include "remotesinksettings.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 08:44:14 +02:00
										 |  |  | #include <QColor>
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | #include "util/simpleserializer.h"
 | 
					
						
							|  |  |  | #include "settings/serializable.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  | RemoteSinkSettings::RemoteSinkSettings() | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     resetToDefaults(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | void RemoteSinkSettings::resetToDefaults() | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     m_nbFECBlocks = 0; | 
					
						
							| 
									
										
										
										
											2021-12-19 13:15:17 +01:00
										 |  |  |     m_nbTxBytes = 2; | 
					
						
							| 
									
										
										
										
											2021-12-23 16:27:19 +01:00
										 |  |  |     m_deviceCenterFrequency = 0; | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  |     m_dataAddress = "127.0.0.1"; | 
					
						
							|  |  |  |     m_dataPort = 9090; | 
					
						
							| 
									
										
										
										
											2018-09-05 18:25:58 +02:00
										 |  |  |     m_rgbColor = QColor(140, 4, 4).rgb(); | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  |     m_title = "Remote sink"; | 
					
						
							| 
									
										
										
										
											2019-04-25 15:48:47 +02:00
										 |  |  |     m_log2Decim = 0; | 
					
						
							|  |  |  |     m_filterChainHash = 0; | 
					
						
							| 
									
										
										
										
											2018-11-18 11:06:41 +01:00
										 |  |  |     m_channelMarker = nullptr; | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |     m_rollupState = nullptr; | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  |     m_streamIndex = 0; | 
					
						
							| 
									
										
										
										
											2018-12-21 17:39:04 +01:00
										 |  |  |     m_useReverseAPI = false; | 
					
						
							|  |  |  |     m_reverseAPIAddress = "127.0.0.1"; | 
					
						
							|  |  |  |     m_reverseAPIPort = 8888; | 
					
						
							|  |  |  |     m_reverseAPIDeviceIndex = 0; | 
					
						
							|  |  |  |     m_reverseAPIChannelIndex = 0; | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | QByteArray RemoteSinkSettings::serialize() const | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     SimpleSerializer s(1); | 
					
						
							|  |  |  |     s.writeU32(1, m_nbFECBlocks); | 
					
						
							| 
									
										
										
										
											2021-12-19 13:15:17 +01:00
										 |  |  |     s.writeU32(2, m_nbTxBytes); | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  |     s.writeString(3, m_dataAddress); | 
					
						
							|  |  |  |     s.writeU32(4, m_dataPort); | 
					
						
							| 
									
										
										
										
											2018-09-05 08:44:14 +02:00
										 |  |  |     s.writeU32(5, m_rgbColor); | 
					
						
							|  |  |  |     s.writeString(6, m_title); | 
					
						
							| 
									
										
										
										
											2018-12-21 17:39:04 +01:00
										 |  |  |     s.writeBool(7, m_useReverseAPI); | 
					
						
							|  |  |  |     s.writeString(8, m_reverseAPIAddress); | 
					
						
							|  |  |  |     s.writeU32(9, m_reverseAPIPort); | 
					
						
							|  |  |  |     s.writeU32(10, m_reverseAPIDeviceIndex); | 
					
						
							|  |  |  |     s.writeU32(11, m_reverseAPIChannelIndex); | 
					
						
							| 
									
										
										
										
											2019-04-25 15:48:47 +02:00
										 |  |  |     s.writeU32(12, m_log2Decim); | 
					
						
							|  |  |  |     s.writeU32(13, m_filterChainHash); | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  |     s.writeS32(14, m_streamIndex); | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |     if (m_rollupState) { | 
					
						
							|  |  |  |         s.writeBlob(15, m_rollupState->serialize()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 16:27:19 +01:00
										 |  |  |     s.writeU64(16, m_deviceCenterFrequency); | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |     if (m_channelMarker) { | 
					
						
							|  |  |  |         s.writeBlob(17, m_channelMarker->serialize()); | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  |     return s.final(); | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  | bool RemoteSinkSettings::deserialize(const QByteArray& data) | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | { | 
					
						
							|  |  |  |     SimpleDeserializer d(data); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(!d.isValid()) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     if(d.getVersion() == 1) | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         uint32_t tmp; | 
					
						
							|  |  |  |         QString strtmp; | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |         QByteArray bytetmp; | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |         d.readU32(1, &tmp, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if (tmp < 128) { | 
					
						
							|  |  |  |             m_nbFECBlocks = tmp; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_nbFECBlocks = 0; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-19 13:15:17 +01:00
										 |  |  |         d.readU32(2, &m_nbTxBytes, 2); | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  |         d.readString(3, &m_dataAddress, "127.0.0.1"); | 
					
						
							|  |  |  |         d.readU32(4, &tmp, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((tmp > 1023) && (tmp < 65535)) { | 
					
						
							|  |  |  |             m_dataPort = tmp; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_dataPort = 9090; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 08:44:14 +02:00
										 |  |  |         d.readU32(5, &m_rgbColor, QColor(0, 255, 255).rgb()); | 
					
						
							| 
									
										
										
										
											2019-01-22 23:39:12 +01:00
										 |  |  |         d.readString(6, &m_title, "Remote sink"); | 
					
						
							| 
									
										
										
										
											2018-12-21 17:39:04 +01:00
										 |  |  |         d.readBool(7, &m_useReverseAPI, false); | 
					
						
							|  |  |  |         d.readString(8, &m_reverseAPIAddress, "127.0.0.1"); | 
					
						
							|  |  |  |         d.readU32(9, &tmp, 0); | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         if ((tmp > 1023) && (tmp < 65535)) { | 
					
						
							|  |  |  |             m_reverseAPIPort = tmp; | 
					
						
							|  |  |  |         } else { | 
					
						
							|  |  |  |             m_reverseAPIPort = 8888; | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |         d.readU32(10, &tmp, 0); | 
					
						
							|  |  |  |         m_reverseAPIDeviceIndex = tmp > 99 ? 99 : tmp; | 
					
						
							|  |  |  |         d.readU32(11, &tmp, 0); | 
					
						
							|  |  |  |         m_reverseAPIChannelIndex = tmp > 99 ? 99 : tmp; | 
					
						
							| 
									
										
										
										
											2019-04-25 15:48:47 +02:00
										 |  |  |         d.readU32(12, &tmp, 0); | 
					
						
							|  |  |  |         m_log2Decim = tmp > 6 ? 6 : tmp; | 
					
						
							|  |  |  |         d.readU32(13, &m_filterChainHash, 0); | 
					
						
							| 
									
										
										
										
											2019-09-23 01:25:17 +02:00
										 |  |  |         d.readS32(14, &m_streamIndex, 0); | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  | 
 | 
					
						
							|  |  |  |         if (m_rollupState) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d.readBlob(15, &bytetmp); | 
					
						
							|  |  |  |             m_rollupState->deserialize(bytetmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2021-12-23 16:27:19 +01:00
										 |  |  |         d.readU64(16, &m_deviceCenterFrequency, 0); | 
					
						
							| 
									
										
										
										
											2018-09-05 08:44:14 +02:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-01-09 05:27:12 +01:00
										 |  |  |         if (m_channelMarker) | 
					
						
							|  |  |  |         { | 
					
						
							|  |  |  |             d.readBlob(17, &bytetmp); | 
					
						
							|  |  |  |             m_channelMarker->deserialize(bytetmp); | 
					
						
							|  |  |  |         } | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-09-05 01:32:29 +02:00
										 |  |  |         return true; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  |     else | 
					
						
							|  |  |  |     { | 
					
						
							|  |  |  |         resetToDefaults(); | 
					
						
							|  |  |  |         return false; | 
					
						
							|  |  |  |     } | 
					
						
							|  |  |  | } | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | 
 |