| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							| 
									
										
										
										
											2023-11-19 06:43:20 +01:00
										 |  |  | // Copyright (C) 2020 Edouard Griffiths, F4EXB <f4exb06@gmail.com>               //
 | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +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                  //
 | 
					
						
							|  |  |  | // (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/>.          //
 | 
					
						
							|  |  |  | ///////////////////////////////////////////////////////////////////////////////////
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #ifndef SDRBASE_WEBSOCKETS_WSSPECTRUM_H_
 | 
					
						
							|  |  |  | #define SDRBASE_WEBSOCKETS_WSSPECTRUM_H_
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <vector>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include <QObject>
 | 
					
						
							|  |  |  | #include <QList>
 | 
					
						
							|  |  |  | #include <QElapsedTimer>
 | 
					
						
							|  |  |  | #include <QHostAddress>
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "dsp/dsptypes.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #include "export.h"
 | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class QWebSocketServer; | 
					
						
							|  |  |  | class QWebSocket; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | class SDRBASE_API WSSpectrum : public QObject | 
					
						
							|  |  |  | { | 
					
						
							|  |  |  |     Q_OBJECT | 
					
						
							|  |  |  | public: | 
					
						
							|  |  |  |     explicit WSSpectrum(QObject *parent = nullptr); | 
					
						
							|  |  |  |     ~WSSpectrum() override; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     void openSocket(); | 
					
						
							|  |  |  |     void closeSocket(); | 
					
						
							| 
									
										
										
										
											2020-05-05 18:58:18 +02:00
										 |  |  |     bool socketOpened() const; | 
					
						
							|  |  |  |     void getPeers(QList<QHostAddress>& hosts, QList<quint16>& ports) const; | 
					
						
							| 
									
										
										
										
											2020-05-11 21:30:10 +02:00
										 |  |  |     void setListeningAddress(const QString& address); | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  |     void setPort(quint16 port) { m_port = port; } | 
					
						
							| 
									
										
										
										
											2020-05-06 17:01:59 +02:00
										 |  |  |     QHostAddress getListeningAddress() const; | 
					
						
							|  |  |  |     uint16_t getListeningPort() const; | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  |     void newSpectrum( | 
					
						
							|  |  |  |         const std::vector<Real>& spectrum, | 
					
						
							|  |  |  |         int fftSize, | 
					
						
							|  |  |  |         uint64_t centerFrequency, | 
					
						
							|  |  |  |         int bandwidth, | 
					
						
							| 
									
										
										
										
											2020-11-11 11:41:49 +01:00
										 |  |  |         bool linear, | 
					
						
							|  |  |  |         bool ssb = false, | 
					
						
							|  |  |  |         bool usb = true | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  |     ); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-05-04 15:28:33 +02:00
										 |  |  | signals: | 
					
						
							|  |  |  |     void payloadToSend(const QByteArray& payload); | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  | private slots: | 
					
						
							|  |  |  |     void onNewConnection(); | 
					
						
							|  |  |  |     void processClientMessage(const QString &message); | 
					
						
							|  |  |  |     void socketDisconnected(); | 
					
						
							| 
									
										
										
										
											2020-05-04 15:28:33 +02:00
										 |  |  |     void sendPayload(const QByteArray& payload); | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  | private: | 
					
						
							|  |  |  |     QHostAddress m_listeningAddress; | 
					
						
							|  |  |  |     quint16 m_port; | 
					
						
							|  |  |  |     QWebSocketServer* m_webSocketServer; | 
					
						
							|  |  |  |     QList<QWebSocket*> m_clients; | 
					
						
							|  |  |  |     QElapsedTimer m_timer; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     static QString getWebSocketIdentifier(QWebSocket *peer); | 
					
						
							|  |  |  |     void buildPayload( | 
					
						
							|  |  |  |         QByteArray& bytes, | 
					
						
							|  |  |  |         const std::vector<Real>& spectrum, | 
					
						
							|  |  |  |         int fftSize, | 
					
						
							|  |  |  |         int64_t fftTimeMs, | 
					
						
							| 
									
										
										
										
											2020-05-04 15:54:24 +02:00
										 |  |  |         uint64_t timestampMs, | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  |         uint64_t centerFrequency, | 
					
						
							|  |  |  |         int bandwidth, | 
					
						
							| 
									
										
										
										
											2020-11-11 11:41:49 +01:00
										 |  |  |         bool linear, | 
					
						
							|  |  |  |         bool ssb, | 
					
						
							|  |  |  |         bool usb | 
					
						
							| 
									
										
										
										
											2020-04-29 17:41:17 +02:00
										 |  |  |     ); | 
					
						
							|  |  |  | }; | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | #endif // SDRBASE_WEBSOCKETS_WSSPECTRUM_H_
 |