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;
33 #warning SPECIFY THIS LATER...
36 timespec_reset(&_lastGUIUpdateTime);
38 _windowOpennedFlag = false;
39 _fftBuffersCreatedFlag = false;
42 //_windowStateLock = new MutexClass("_windowStateLock");
47 SpectrumGUIClass::~SpectrumGUIClass()
49 if(GetWindowOpenFlag()){
50 delete _spectrumDisplayForm;
53 if(_fftBuffersCreatedFlag){
55 delete[] _realTimeDomainPoints;
56 delete[] _imagTimeDomainPoints;
59 //delete _windowStateLock;
63 SpectrumGUIClass::OpenSpectrumWindow(QWidget* parent,
64 const bool frequency, const bool waterfall,
65 const bool waterfall3d, const bool time,
66 const bool constellation,
67 const bool use_openGL)
69 //_windowStateLock->Lock();
71 if(!_windowOpennedFlag){
73 if(!_fftBuffersCreatedFlag){
74 _fftPoints = new std::complex<float>[_dataPoints];
75 _realTimeDomainPoints = new double[_dataPoints];
76 _imagTimeDomainPoints = new double[_dataPoints];
77 _fftBuffersCreatedFlag = true;
80 memset(_fftPoints, 0x0, _dataPoints*sizeof(std::complex<float>));
81 memset(_realTimeDomainPoints, 0x0, _dataPoints*sizeof(double));
82 memset(_imagTimeDomainPoints, 0x0, _dataPoints*sizeof(double));
85 // Called from the Event Thread
86 _spectrumDisplayForm = new SpectrumDisplayForm(use_openGL, parent);
88 // Toggle Windows on/off
89 _spectrumDisplayForm->ToggleTabFrequency(frequency);
90 _spectrumDisplayForm->ToggleTabWaterfall(waterfall);
91 _spectrumDisplayForm->ToggleTabWaterfall3D(waterfall3d);
92 _spectrumDisplayForm->ToggleTabTime(time);
93 _spectrumDisplayForm->ToggleTabConstellation(constellation);
95 _windowOpennedFlag = true;
97 _spectrumDisplayForm->setSystem(this, _dataPoints, _fftSize);
99 qApp->processEvents();
102 //_windowStateLock->Unlock();
104 SetDisplayTitle(_title);
107 qApp->postEvent(_spectrumDisplayForm,
108 new QEvent(QEvent::Type(QEvent::User+3)));
110 qApp->processEvents();
112 timespec_reset(&_lastGUIUpdateTime);
114 // Draw Blank Display
115 UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, 1.0, get_highres_clock(), true);
117 // Set up the initial frequency axis settings
118 SetFrequencyRange(_centerFrequency, _startFrequency, _stopFrequency);
121 qApp->processEvents();
125 SpectrumGUIClass::Reset()
127 if(GetWindowOpenFlag()) {
128 qApp->postEvent(_spectrumDisplayForm,
129 new SpectrumFrequencyRangeEvent(_centerFrequency,
132 qApp->postEvent(_spectrumDisplayForm, new SpectrumWindowResetEvent());
134 _droppedEntriesCount = 0;
135 // Call the following function the the Spectrum Window Reset Event window
136 // ResetPendingGUIUpdateEvents();
140 SpectrumGUIClass::SetDisplayTitle(const std::string newString)
142 _title.assign(newString);
144 if(GetWindowOpenFlag()){
145 qApp->postEvent(_spectrumDisplayForm,
146 new SpectrumWindowCaptionEvent(_title.c_str()));
151 SpectrumGUIClass::GetWindowOpenFlag()
153 bool returnFlag = false;
154 //_windowStateLock->Lock();
155 returnFlag = _windowOpennedFlag;
156 //_windowStateLock->Unlock();
162 SpectrumGUIClass::SetWindowOpenFlag(const bool newFlag)
164 //_windowStateLock->Lock();
165 _windowOpennedFlag = newFlag;
166 //_windowStateLock->Unlock();
170 SpectrumGUIClass::SetFrequencyRange(const double centerFreq,
171 const double startFreq,
172 const double stopFreq)
174 //_windowStateLock->Lock();
175 _centerFrequency = centerFreq;
176 _startFrequency = startFreq;
177 _stopFrequency = stopFreq;
179 _spectrumDisplayForm->SetFrequencyRange(_centerFrequency,
182 //_windowStateLock->Unlock();
186 SpectrumGUIClass::GetStartFrequency() const
188 double returnValue = 0.0;
189 //_windowStateLock->Lock();
190 returnValue = _startFrequency;
191 //_windowStateLock->Unlock();
196 SpectrumGUIClass::GetStopFrequency() const
198 double returnValue = 0.0;
199 //_windowStateLock->Lock();
200 returnValue = _stopFrequency;
201 //_windowStateLock->Unlock();
206 SpectrumGUIClass::GetCenterFrequency() const
208 double returnValue = 0.0;
209 //_windowStateLock->Lock();
210 returnValue = _centerFrequency;
211 //_windowStateLock->Unlock();
217 SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag,
218 const std::complex<float>* fftBuffer,
219 const uint64_t inputBufferSize,
220 const float* realTimeDomainData,
221 const uint64_t realTimeDomainDataSize,
222 const float* complexTimeDomainData,
223 const uint64_t complexTimeDomainDataSize,
224 const double timePerFFT,
225 const timespec timestamp,
226 const bool lastOfMultipleFFTUpdateFlag)
228 int64_t bufferSize = inputBufferSize;
229 bool repeatDataFlag = false;
230 if(bufferSize > _dataPoints){
231 bufferSize = _dataPoints;
233 int64_t timeDomainBufferSize = 0;
235 if(updateDisplayFlag){
236 if((fftBuffer != NULL) && (bufferSize > 0)){
237 memcpy(_fftPoints, fftBuffer, bufferSize * sizeof(std::complex<float>));
240 // Can't do a memcpy since ths is going from float to double data type
241 if((realTimeDomainData != NULL) && (realTimeDomainDataSize > 0)){
242 const float* realTimeDomainDataPtr = realTimeDomainData;
244 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
245 timeDomainBufferSize = realTimeDomainDataSize;
247 memset( _imagTimeDomainPoints, 0x0, realTimeDomainDataSize*sizeof(double));
248 for( uint64_t number = 0; number < realTimeDomainDataSize; number++){
249 *realTimeDomainPointsPtr++ = *realTimeDomainDataPtr++;
253 // Can't do a memcpy since ths is going from float to double data type
254 if((complexTimeDomainData != NULL) && (complexTimeDomainDataSize > 0)){
255 const float* complexTimeDomainDataPtr = complexTimeDomainData;
257 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
258 double* imagTimeDomainPointsPtr = _imagTimeDomainPoints;
260 timeDomainBufferSize = complexTimeDomainDataSize;
261 for( uint64_t number = 0; number < complexTimeDomainDataSize; number++){
262 *realTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
263 *imagTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
268 // If bufferSize is zero, then just update the display by sending over the old data
270 bufferSize = _lastDataPointCount;
271 repeatDataFlag = true;
274 // Since there is data this time, update the count
275 _lastDataPointCount = bufferSize;
278 const timespec currentTime = get_highres_clock();
279 const timespec lastUpdateGUITime = GetLastGUIUpdateTime();
281 if((diff_timespec(currentTime, lastUpdateGUITime) > (4*timePerFFT)) &&
282 (GetPendingGUIUpdateEvents() > 0) && !timespec_empty(&lastUpdateGUITime)) {
283 // Do not update the display if too much data is pending to be displayed
284 _droppedEntriesCount++;
288 IncrementPendingGUIUpdateEvents();
289 qApp->postEvent(_spectrumDisplayForm,
290 new SpectrumUpdateEvent(_fftPoints, bufferSize,
291 _realTimeDomainPoints,
292 _imagTimeDomainPoints,
293 timeDomainBufferSize,
294 timePerFFT, timestamp,
296 lastOfMultipleFFTUpdateFlag,
298 _droppedEntriesCount));
300 // Only reset the dropped entries counter if this is not
301 // repeat data since repeat data is dropped by the display systems
303 _droppedEntriesCount = 0;
309 SpectrumGUIClass::GetPowerValue() const
311 float returnValue = 0;
312 //_windowStateLock->Lock();
313 returnValue = _powerValue;
314 //_windowStateLock->Unlock();
319 SpectrumGUIClass::SetPowerValue(const float value)
321 //_windowStateLock->Lock();
323 //_windowStateLock->Unlock();
327 SpectrumGUIClass::GetWindowType() const
330 //_windowStateLock->Lock();
331 returnValue = _windowType;
332 //_windowStateLock->Unlock();
337 SpectrumGUIClass::SetWindowType(const int newType)
339 //_windowStateLock->Lock();
340 _windowType = newType;
341 //_windowStateLock->Unlock();
345 SpectrumGUIClass::GetFFTSize() const
348 //_windowStateLock->Lock();
349 returnValue = _fftSize;
350 //_windowStateLock->Unlock();
355 SpectrumGUIClass::GetFFTSizeIndex() const
357 int fftsize = GetFFTSize();
359 case(1024): return 0; break;
360 case(2048): return 1; break;
361 case(4096): return 2; break;
362 case(8192): return 3; break;
363 case(16384): return 3; break;
364 case(32768): return 3; break;
370 SpectrumGUIClass::SetFFTSize(const int newSize)
372 //_windowStateLock->Lock();
374 //_windowStateLock->Unlock();
378 SpectrumGUIClass::GetLastGUIUpdateTime() const
380 timespec returnValue;
381 //_windowStateLock->Lock();
382 returnValue = _lastGUIUpdateTime;
383 //_windowStateLock->Unlock();
388 SpectrumGUIClass::SetLastGUIUpdateTime(const timespec newTime)
390 //_windowStateLock->Lock();
391 _lastGUIUpdateTime = newTime;
392 //_windowStateLock->Unlock();
396 SpectrumGUIClass::GetPendingGUIUpdateEvents() const
398 unsigned int returnValue = 0;
399 //_windowStateLock->Lock();
400 returnValue = _pendingGUIUpdateEventsCount;
401 //_windowStateLock->Unlock();
406 SpectrumGUIClass::IncrementPendingGUIUpdateEvents()
408 //_windowStateLock->Lock();
409 _pendingGUIUpdateEventsCount++;
410 //_windowStateLock->Unlock();
414 SpectrumGUIClass::DecrementPendingGUIUpdateEvents()
416 //_windowStateLock->Lock();
417 if(_pendingGUIUpdateEventsCount > 0){
418 _pendingGUIUpdateEventsCount--;
420 //_windowStateLock->Unlock();
424 SpectrumGUIClass::ResetPendingGUIUpdateEvents()
426 //_windowStateLock->Lock();
427 _pendingGUIUpdateEventsCount = 0;
428 //_windowStateLock->Unlock();
433 SpectrumGUIClass::qwidget()
435 return (QWidget*)_spectrumDisplayForm;
439 SpectrumGUIClass::SetTimeDomainAxis(double min, double max)
441 _spectrumDisplayForm->SetTimeDomainAxis(min, max);
445 SpectrumGUIClass::SetConstellationAxis(double xmin, double xmax,
446 double ymin, double ymax)
448 _spectrumDisplayForm->SetConstellationAxis(xmin, xmax, ymin, ymax);
453 SpectrumGUIClass::SetFrequencyAxis(double min, double max)
455 _spectrumDisplayForm->SetFrequencyAxis(min, max);
458 #endif /* SPECTRUM_GUI_CLASS_CPP */