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, 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 timespec timestamp,
224 const bool lastOfMultipleFFTUpdateFlag)
226 int64_t bufferSize = inputBufferSize;
227 bool repeatDataFlag = false;
228 if(bufferSize > _dataPoints){
229 bufferSize = _dataPoints;
231 int64_t timeDomainBufferSize = 0;
233 if(updateDisplayFlag){
234 if((fftBuffer != NULL) && (bufferSize > 0)){
235 memcpy(_fftPoints, fftBuffer, bufferSize * sizeof(std::complex<float>));
238 // Can't do a memcpy since ths is going from float to double data type
239 if((realTimeDomainData != NULL) && (realTimeDomainDataSize > 0)){
240 const float* realTimeDomainDataPtr = realTimeDomainData;
242 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
243 timeDomainBufferSize = realTimeDomainDataSize;
245 memset( _imagTimeDomainPoints, 0x0, realTimeDomainDataSize*sizeof(double));
246 for( uint64_t number = 0; number < realTimeDomainDataSize; number++){
247 *realTimeDomainPointsPtr++ = *realTimeDomainDataPtr++;
251 // Can't do a memcpy since ths is going from float to double data type
252 if((complexTimeDomainData != NULL) && (complexTimeDomainDataSize > 0)){
253 const float* complexTimeDomainDataPtr = complexTimeDomainData;
255 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
256 double* imagTimeDomainPointsPtr = _imagTimeDomainPoints;
258 timeDomainBufferSize = complexTimeDomainDataSize;
259 for( uint64_t number = 0; number < complexTimeDomainDataSize; number++){
260 *realTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
261 *imagTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
266 // If bufferSize is zero, then just update the display by sending over the old data
268 bufferSize = _lastDataPointCount;
269 repeatDataFlag = true;
272 // Since there is data this time, update the count
273 _lastDataPointCount = bufferSize;
276 const timespec currentTime = get_highres_clock();
277 const timespec lastUpdateGUITime = GetLastGUIUpdateTime();
279 if((diff_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) &&
280 (GetPendingGUIUpdateEvents() > 0) && !timespec_empty(&lastUpdateGUITime)) {
281 // Do not update the display if too much data is pending to be displayed
282 _droppedEntriesCount++;
286 IncrementPendingGUIUpdateEvents();
287 qApp->postEvent(_spectrumDisplayForm,
288 new SpectrumUpdateEvent(_fftPoints, bufferSize,
289 _realTimeDomainPoints,
290 _imagTimeDomainPoints,
291 timeDomainBufferSize,
294 lastOfMultipleFFTUpdateFlag,
296 _droppedEntriesCount));
298 // Only reset the dropped entries counter if this is not
299 // repeat data since repeat data is dropped by the display systems
301 _droppedEntriesCount = 0;
307 SpectrumGUIClass::GetPowerValue() const
309 float returnValue = 0;
310 //_windowStateLock->Lock();
311 returnValue = _powerValue;
312 //_windowStateLock->Unlock();
317 SpectrumGUIClass::SetPowerValue(const float value)
319 //_windowStateLock->Lock();
321 //_windowStateLock->Unlock();
325 SpectrumGUIClass::GetWindowType() const
328 //_windowStateLock->Lock();
329 returnValue = _windowType;
330 //_windowStateLock->Unlock();
335 SpectrumGUIClass::SetWindowType(const int newType)
337 //_windowStateLock->Lock();
338 _windowType = newType;
339 //_windowStateLock->Unlock();
343 SpectrumGUIClass::GetFFTSize() const
346 //_windowStateLock->Lock();
347 returnValue = _fftSize;
348 //_windowStateLock->Unlock();
353 SpectrumGUIClass::GetFFTSizeIndex() const
355 int fftsize = GetFFTSize();
357 case(1024): return 0; break;
358 case(2048): return 1; break;
359 case(4096): return 2; break;
360 case(8192): return 3; break;
361 case(16384): return 3; break;
362 case(32768): return 3; break;
368 SpectrumGUIClass::SetFFTSize(const int newSize)
370 //_windowStateLock->Lock();
372 //_windowStateLock->Unlock();
376 SpectrumGUIClass::GetLastGUIUpdateTime() const
378 timespec returnValue;
379 //_windowStateLock->Lock();
380 returnValue = _lastGUIUpdateTime;
381 //_windowStateLock->Unlock();
386 SpectrumGUIClass::SetLastGUIUpdateTime(const timespec newTime)
388 //_windowStateLock->Lock();
389 _lastGUIUpdateTime = newTime;
390 //_windowStateLock->Unlock();
394 SpectrumGUIClass::GetPendingGUIUpdateEvents() const
396 unsigned int returnValue = 0;
397 //_windowStateLock->Lock();
398 returnValue = _pendingGUIUpdateEventsCount;
399 //_windowStateLock->Unlock();
404 SpectrumGUIClass::IncrementPendingGUIUpdateEvents()
406 //_windowStateLock->Lock();
407 _pendingGUIUpdateEventsCount++;
408 //_windowStateLock->Unlock();
412 SpectrumGUIClass::DecrementPendingGUIUpdateEvents()
414 //_windowStateLock->Lock();
415 if(_pendingGUIUpdateEventsCount > 0){
416 _pendingGUIUpdateEventsCount--;
418 //_windowStateLock->Unlock();
422 SpectrumGUIClass::ResetPendingGUIUpdateEvents()
424 //_windowStateLock->Lock();
425 _pendingGUIUpdateEventsCount = 0;
426 //_windowStateLock->Unlock();
431 SpectrumGUIClass::qwidget()
433 return (QWidget*)_spectrumDisplayForm;
437 SpectrumGUIClass::SetTimeDomainAxis(double min, double max)
439 _spectrumDisplayForm->SetTimeDomainAxis(min, max);
443 SpectrumGUIClass::SetConstellationAxis(double xmin, double xmax,
444 double ymin, double ymax)
446 _spectrumDisplayForm->SetConstellationAxis(xmin, xmax, ymin, ymax);
451 SpectrumGUIClass::SetConstellationPenSize(int size){
452 _spectrumDisplayForm->SetConstellationPenSize(size);
457 SpectrumGUIClass::SetFrequencyAxis(double min, double max)
459 _spectrumDisplayForm->SetFrequencyAxis(min, max);
463 SpectrumGUIClass::SetUpdateTime(double t)
466 _spectrumDisplayForm->SetUpdateTime(_updateTime);
470 #endif /* SPECTRUM_GUI_CLASS_CPP */