1 #ifndef SPECTRUM_GUI_CLASS_CPP
2 #define SPECTRUM_GUI_CLASS_CPP
4 #include <SpectrumGUIClass.h>
7 #include <QCustomEvent>
9 const long SpectrumGUIClass::MAX_FFT_SIZE;
10 const long SpectrumGUIClass::MIN_FFT_SIZE;
12 SpectrumGUIClass::SpectrumGUIClass(const uint64_t maxDataSize,
13 const uint64_t fftSize,
14 const double newCenterFrequency,
15 const double newStartFrequency,
16 const double newStopFrequency)
18 _dataPoints = maxDataSize;
22 _lastDataPointCount = _dataPoints;
26 _pendingGUIUpdateEventsCount = 0;
27 _droppedEntriesCount = 0;
29 _centerFrequency = newCenterFrequency;
30 _startFrequency = newStartFrequency;
31 _stopFrequency = newStopFrequency;
35 timespec_reset(&_lastGUIUpdateTime);
37 _windowOpennedFlag = false;
38 _fftBuffersCreatedFlag = false;
41 //_windowStateLock = new MutexClass("_windowStateLock");
46 SpectrumGUIClass::~SpectrumGUIClass()
48 if(GetWindowOpenFlag()){
49 delete _spectrumDisplayForm;
52 if(_fftBuffersCreatedFlag){
54 delete[] _realTimeDomainPoints;
55 delete[] _imagTimeDomainPoints;
58 //delete _windowStateLock;
62 SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent,
63 const bool frequency, const bool waterfall,
64 const bool waterfall3d, const bool time,
65 const bool constellation,
66 const bool use_openGL)
68 //_windowStateLock->Lock();
70 if(!_windowOpennedFlag){
72 if(!_fftBuffersCreatedFlag){
73 _fftPoints = new std::complex<float>[_dataPoints];
74 _realTimeDomainPoints = new double[_dataPoints];
75 _imagTimeDomainPoints = new double[_dataPoints];
76 _fftBuffersCreatedFlag = true;
79 memset(_fftPoints, 0x0, _dataPoints*sizeof(std::complex<float>));
80 memset(_realTimeDomainPoints, 0x0, _dataPoints*sizeof(double));
81 memset(_imagTimeDomainPoints, 0x0, _dataPoints*sizeof(double));
84 // Called from the Event Thread
85 _spectrumDisplayForm = new SpectrumDisplayForm(use_openGL, parent);
87 // Toggle Windows on/off
88 _spectrumDisplayForm->ToggleTabFrequency(frequency);
89 _spectrumDisplayForm->ToggleTabWaterfall(waterfall);
90 _spectrumDisplayForm->ToggleTabWaterfall3D(waterfall3d);
91 _spectrumDisplayForm->ToggleTabTime(time);
92 _spectrumDisplayForm->ToggleTabConstellation(constellation);
94 _windowOpennedFlag = true;
96 _spectrumDisplayForm->setSystem(this, _dataPoints, _fftSize);
98 qApp->processEvents();
101 //_windowStateLock->Unlock();
103 SetDisplayTitle(_title);
106 qApp->postEvent(_spectrumDisplayForm,
107 new QEvent(QEvent::Type(QEvent::User+3)));
109 qApp->processEvents();
111 timespec_reset(&_lastGUIUpdateTime);
113 // Draw Blank Display
114 UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, 1.0, get_highres_clock(), true);
116 // Set up the initial frequency axis settings
117 SetFrequencyRange(_centerFrequency, _startFrequency, _stopFrequency);
120 qApp->processEvents();
124 SpectrumGUIClass::Reset()
126 if(GetWindowOpenFlag()) {
127 qApp->postEvent(_spectrumDisplayForm,
128 new SpectrumFrequencyRangeEvent(_centerFrequency,
131 qApp->postEvent(_spectrumDisplayForm, new SpectrumWindowResetEvent());
133 _droppedEntriesCount = 0;
134 // Call the following function the the Spectrum Window Reset Event window
135 // ResetPendingGUIUpdateEvents();
139 SpectrumGUIClass::SetDisplayTitle(const std::string newString)
141 _title.assign(newString);
143 if(GetWindowOpenFlag()){
144 qApp->postEvent(_spectrumDisplayForm,
145 new SpectrumWindowCaptionEvent(_title.c_str()));
150 SpectrumGUIClass::GetWindowOpenFlag()
152 bool returnFlag = false;
153 //_windowStateLock->Lock();
154 returnFlag = _windowOpennedFlag;
155 //_windowStateLock->Unlock();
161 SpectrumGUIClass::SetWindowOpenFlag(const bool newFlag)
163 //_windowStateLock->Lock();
164 _windowOpennedFlag = newFlag;
165 //_windowStateLock->Unlock();
169 SpectrumGUIClass::SetFrequencyRange(const double centerFreq,
170 const double startFreq,
171 const double stopFreq)
173 //_windowStateLock->Lock();
174 _centerFrequency = centerFreq;
175 _startFrequency = startFreq;
176 _stopFrequency = stopFreq;
178 _spectrumDisplayForm->SetFrequencyRange(_centerFrequency,
181 //_windowStateLock->Unlock();
185 SpectrumGUIClass::GetStartFrequency() const
187 double returnValue = 0.0;
188 //_windowStateLock->Lock();
189 returnValue = _startFrequency;
190 //_windowStateLock->Unlock();
195 SpectrumGUIClass::GetStopFrequency() const
197 double returnValue = 0.0;
198 //_windowStateLock->Lock();
199 returnValue = _stopFrequency;
200 //_windowStateLock->Unlock();
205 SpectrumGUIClass::GetCenterFrequency() const
207 double returnValue = 0.0;
208 //_windowStateLock->Lock();
209 returnValue = _centerFrequency;
210 //_windowStateLock->Unlock();
216 SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag,
217 const std::complex<float>* fftBuffer,
218 const uint64_t inputBufferSize,
219 const float* realTimeDomainData,
220 const uint64_t realTimeDomainDataSize,
221 const float* complexTimeDomainData,
222 const uint64_t complexTimeDomainDataSize,
223 const double timePerFFT,
224 const timespec timestamp,
225 const bool lastOfMultipleFFTUpdateFlag)
227 int64_t bufferSize = inputBufferSize;
228 bool repeatDataFlag = false;
229 if(bufferSize > _dataPoints){
230 bufferSize = _dataPoints;
232 int64_t timeDomainBufferSize = 0;
234 if(updateDisplayFlag){
235 if((fftBuffer != NULL) && (bufferSize > 0)){
236 memcpy(_fftPoints, fftBuffer, bufferSize * sizeof(std::complex<float>));
239 // Can't do a memcpy since ths is going from float to double data type
240 if((realTimeDomainData != NULL) && (realTimeDomainDataSize > 0)){
241 const float* realTimeDomainDataPtr = realTimeDomainData;
243 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
244 timeDomainBufferSize = realTimeDomainDataSize;
246 memset( _imagTimeDomainPoints, 0x0, realTimeDomainDataSize*sizeof(double));
247 for( uint64_t number = 0; number < realTimeDomainDataSize; number++){
248 *realTimeDomainPointsPtr++ = *realTimeDomainDataPtr++;
252 // Can't do a memcpy since ths is going from float to double data type
253 if((complexTimeDomainData != NULL) && (complexTimeDomainDataSize > 0)){
254 const float* complexTimeDomainDataPtr = complexTimeDomainData;
256 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
257 double* imagTimeDomainPointsPtr = _imagTimeDomainPoints;
259 timeDomainBufferSize = complexTimeDomainDataSize;
260 for( uint64_t number = 0; number < complexTimeDomainDataSize; number++){
261 *realTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
262 *imagTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
267 // If bufferSize is zero, then just update the display by sending over the old data
269 bufferSize = _lastDataPointCount;
270 repeatDataFlag = true;
273 // Since there is data this time, update the count
274 _lastDataPointCount = bufferSize;
277 const timespec currentTime = get_highres_clock();
278 const timespec lastUpdateGUITime = GetLastGUIUpdateTime();
280 if((diff_timespec(currentTime, lastUpdateGUITime) > (4*timePerFFT)) &&
281 (GetPendingGUIUpdateEvents() > 0) && !timespec_empty(&lastUpdateGUITime)) {
282 // Do not update the display if too much data is pending to be displayed
283 _droppedEntriesCount++;
287 IncrementPendingGUIUpdateEvents();
288 qApp->postEvent(_spectrumDisplayForm,
289 new SpectrumUpdateEvent(_fftPoints, bufferSize,
290 _realTimeDomainPoints,
291 _imagTimeDomainPoints,
292 timeDomainBufferSize,
293 timePerFFT, timestamp,
295 lastOfMultipleFFTUpdateFlag,
297 _droppedEntriesCount));
299 // Only reset the dropped entries counter if this is not
300 // repeat data since repeat data is dropped by the display systems
302 _droppedEntriesCount = 0;
308 SpectrumGUIClass::GetPowerValue() const
310 float returnValue = 0;
311 //_windowStateLock->Lock();
312 returnValue = _powerValue;
313 //_windowStateLock->Unlock();
318 SpectrumGUIClass::SetPowerValue(const float value)
320 //_windowStateLock->Lock();
322 //_windowStateLock->Unlock();
326 SpectrumGUIClass::GetWindowType() const
329 //_windowStateLock->Lock();
330 returnValue = _windowType;
331 //_windowStateLock->Unlock();
336 SpectrumGUIClass::SetWindowType(const int newType)
338 //_windowStateLock->Lock();
339 _windowType = newType;
340 //_windowStateLock->Unlock();
344 SpectrumGUIClass::GetFFTSize() const
347 //_windowStateLock->Lock();
348 returnValue = _fftSize;
349 //_windowStateLock->Unlock();
354 SpectrumGUIClass::GetFFTSizeIndex() const
356 int fftsize = GetFFTSize();
358 case(1024): return 0; break;
359 case(2048): return 1; break;
360 case(4096): return 2; break;
361 case(8192): return 3; break;
362 case(16384): return 3; break;
363 case(32768): return 3; break;
369 SpectrumGUIClass::SetFFTSize(const int newSize)
371 //_windowStateLock->Lock();
373 //_windowStateLock->Unlock();
377 SpectrumGUIClass::GetLastGUIUpdateTime() const
379 timespec returnValue;
380 //_windowStateLock->Lock();
381 returnValue = _lastGUIUpdateTime;
382 //_windowStateLock->Unlock();
387 SpectrumGUIClass::SetLastGUIUpdateTime(const timespec newTime)
389 //_windowStateLock->Lock();
390 _lastGUIUpdateTime = newTime;
391 //_windowStateLock->Unlock();
395 SpectrumGUIClass::GetPendingGUIUpdateEvents() const
397 unsigned int returnValue = 0;
398 //_windowStateLock->Lock();
399 returnValue = _pendingGUIUpdateEventsCount;
400 //_windowStateLock->Unlock();
405 SpectrumGUIClass::IncrementPendingGUIUpdateEvents()
407 //_windowStateLock->Lock();
408 _pendingGUIUpdateEventsCount++;
409 //_windowStateLock->Unlock();
413 SpectrumGUIClass::DecrementPendingGUIUpdateEvents()
415 //_windowStateLock->Lock();
416 if(_pendingGUIUpdateEventsCount > 0){
417 _pendingGUIUpdateEventsCount--;
419 //_windowStateLock->Unlock();
423 SpectrumGUIClass::ResetPendingGUIUpdateEvents()
425 //_windowStateLock->Lock();
426 _pendingGUIUpdateEventsCount = 0;
427 //_windowStateLock->Unlock();
432 SpectrumGUIClass::qwidget()
434 return (QWidget*)_spectrumDisplayForm;
438 SpectrumGUIClass::SetTimeDomainAxis(double min, double max)
440 _spectrumDisplayForm->SetTimeDomainAxis(min, max);
444 SpectrumGUIClass::SetConstellationAxis(double xmin, double xmax,
445 double ymin, double ymax)
447 _spectrumDisplayForm->SetConstellationAxis(xmin, xmax, ymin, ymax);
452 SpectrumGUIClass::SetConstellationPenSize(int size){
453 _spectrumDisplayForm->SetConstellationPenSize(size);
458 SpectrumGUIClass::SetFrequencyAxis(double min, double max)
460 _spectrumDisplayForm->SetFrequencyAxis(min, max);
463 #endif /* SPECTRUM_GUI_CLASS_CPP */