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 time, const bool constellation,
65 const bool use_openGL)
67 //_windowStateLock->Lock();
69 if(!_windowOpennedFlag){
71 if(!_fftBuffersCreatedFlag){
72 _fftPoints = new std::complex<float>[_dataPoints];
73 _realTimeDomainPoints = new double[_dataPoints];
74 _imagTimeDomainPoints = new double[_dataPoints];
75 _fftBuffersCreatedFlag = true;
78 memset(_fftPoints, 0x0, _dataPoints*sizeof(std::complex<float>));
79 memset(_realTimeDomainPoints, 0x0, _dataPoints*sizeof(double));
80 memset(_imagTimeDomainPoints, 0x0, _dataPoints*sizeof(double));
83 // Called from the Event Thread
84 _spectrumDisplayForm = new SpectrumDisplayForm(use_openGL, parent);
86 // Toggle Windows on/off
87 _spectrumDisplayForm->ToggleTabFrequency(frequency);
88 _spectrumDisplayForm->ToggleTabWaterfall(waterfall);
89 _spectrumDisplayForm->ToggleTabTime(time);
90 _spectrumDisplayForm->ToggleTabConstellation(constellation);
92 _windowOpennedFlag = true;
94 _spectrumDisplayForm->setSystem(this, _dataPoints, _fftSize);
96 qApp->processEvents();
99 //_windowStateLock->Unlock();
101 SetDisplayTitle(_title);
104 qApp->postEvent(_spectrumDisplayForm,
105 new QEvent(QEvent::Type(QEvent::User+3)));
107 qApp->processEvents();
109 timespec_reset(&_lastGUIUpdateTime);
111 // Draw Blank Display
112 UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, get_highres_clock(), true);
114 // Set up the initial frequency axis settings
115 SetFrequencyRange(_centerFrequency, _startFrequency, _stopFrequency);
118 qApp->processEvents();
122 SpectrumGUIClass::Reset()
124 if(GetWindowOpenFlag()) {
125 qApp->postEvent(_spectrumDisplayForm,
126 new SpectrumFrequencyRangeEvent(_centerFrequency,
129 qApp->postEvent(_spectrumDisplayForm, new SpectrumWindowResetEvent());
131 _droppedEntriesCount = 0;
132 // Call the following function the the Spectrum Window Reset Event window
133 // ResetPendingGUIUpdateEvents();
137 SpectrumGUIClass::SetDisplayTitle(const std::string newString)
139 _title.assign(newString);
141 if(GetWindowOpenFlag()){
142 qApp->postEvent(_spectrumDisplayForm,
143 new SpectrumWindowCaptionEvent(_title.c_str()));
148 SpectrumGUIClass::GetWindowOpenFlag()
150 bool returnFlag = false;
151 //_windowStateLock->Lock();
152 returnFlag = _windowOpennedFlag;
153 //_windowStateLock->Unlock();
159 SpectrumGUIClass::SetWindowOpenFlag(const bool newFlag)
161 //_windowStateLock->Lock();
162 _windowOpennedFlag = newFlag;
163 //_windowStateLock->Unlock();
167 SpectrumGUIClass::SetFrequencyRange(const double centerFreq,
168 const double startFreq,
169 const double stopFreq)
171 //_windowStateLock->Lock();
172 _centerFrequency = centerFreq;
173 _startFrequency = startFreq;
174 _stopFrequency = stopFreq;
176 _spectrumDisplayForm->SetFrequencyRange(_centerFrequency,
179 //_windowStateLock->Unlock();
183 SpectrumGUIClass::GetStartFrequency() const
185 double returnValue = 0.0;
186 //_windowStateLock->Lock();
187 returnValue = _startFrequency;
188 //_windowStateLock->Unlock();
193 SpectrumGUIClass::GetStopFrequency() const
195 double returnValue = 0.0;
196 //_windowStateLock->Lock();
197 returnValue = _stopFrequency;
198 //_windowStateLock->Unlock();
203 SpectrumGUIClass::GetCenterFrequency() const
205 double returnValue = 0.0;
206 //_windowStateLock->Lock();
207 returnValue = _centerFrequency;
208 //_windowStateLock->Unlock();
214 SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag,
215 const std::complex<float>* fftBuffer,
216 const uint64_t inputBufferSize,
217 const float* realTimeDomainData,
218 const uint64_t realTimeDomainDataSize,
219 const float* complexTimeDomainData,
220 const uint64_t complexTimeDomainDataSize,
221 const timespec timestamp,
222 const bool lastOfMultipleFFTUpdateFlag)
224 int64_t bufferSize = inputBufferSize;
225 bool repeatDataFlag = false;
226 if(bufferSize > _dataPoints){
227 bufferSize = _dataPoints;
229 int64_t timeDomainBufferSize = 0;
231 if(updateDisplayFlag){
232 if((fftBuffer != NULL) && (bufferSize > 0)){
233 memcpy(_fftPoints, fftBuffer, bufferSize * sizeof(std::complex<float>));
236 // Can't do a memcpy since ths is going from float to double data type
237 if((realTimeDomainData != NULL) && (realTimeDomainDataSize > 0)){
238 const float* realTimeDomainDataPtr = realTimeDomainData;
240 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
241 timeDomainBufferSize = realTimeDomainDataSize;
243 memset( _imagTimeDomainPoints, 0x0, realTimeDomainDataSize*sizeof(double));
244 for( uint64_t number = 0; number < realTimeDomainDataSize; number++){
245 *realTimeDomainPointsPtr++ = *realTimeDomainDataPtr++;
249 // Can't do a memcpy since ths is going from float to double data type
250 if((complexTimeDomainData != NULL) && (complexTimeDomainDataSize > 0)){
251 const float* complexTimeDomainDataPtr = complexTimeDomainData;
253 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
254 double* imagTimeDomainPointsPtr = _imagTimeDomainPoints;
256 timeDomainBufferSize = complexTimeDomainDataSize;
257 for( uint64_t number = 0; number < complexTimeDomainDataSize; number++){
258 *realTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
259 *imagTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
264 // If bufferSize is zero, then just update the display by sending over the old data
266 bufferSize = _lastDataPointCount;
267 repeatDataFlag = true;
270 // Since there is data this time, update the count
271 _lastDataPointCount = bufferSize;
274 const timespec currentTime = get_highres_clock();
275 const timespec lastUpdateGUITime = GetLastGUIUpdateTime();
277 if((diff_timespec(currentTime, lastUpdateGUITime) > (4*_updateTime)) &&
278 (GetPendingGUIUpdateEvents() > 0) && !timespec_empty(&lastUpdateGUITime)) {
279 // Do not update the display if too much data is pending to be displayed
280 _droppedEntriesCount++;
284 IncrementPendingGUIUpdateEvents();
285 qApp->postEvent(_spectrumDisplayForm,
286 new SpectrumUpdateEvent(_fftPoints, bufferSize,
287 _realTimeDomainPoints,
288 _imagTimeDomainPoints,
289 timeDomainBufferSize,
292 lastOfMultipleFFTUpdateFlag,
294 _droppedEntriesCount));
296 // Only reset the dropped entries counter if this is not
297 // repeat data since repeat data is dropped by the display systems
299 _droppedEntriesCount = 0;
305 SpectrumGUIClass::GetPowerValue() const
307 float returnValue = 0;
308 //_windowStateLock->Lock();
309 returnValue = _powerValue;
310 //_windowStateLock->Unlock();
315 SpectrumGUIClass::SetPowerValue(const float value)
317 //_windowStateLock->Lock();
319 //_windowStateLock->Unlock();
323 SpectrumGUIClass::GetWindowType() const
326 //_windowStateLock->Lock();
327 returnValue = _windowType;
328 //_windowStateLock->Unlock();
333 SpectrumGUIClass::SetWindowType(const int newType)
335 //_windowStateLock->Lock();
336 _windowType = newType;
337 //_windowStateLock->Unlock();
341 SpectrumGUIClass::GetFFTSize() const
344 //_windowStateLock->Lock();
345 returnValue = _fftSize;
346 //_windowStateLock->Unlock();
351 SpectrumGUIClass::GetFFTSizeIndex() const
353 int fftsize = GetFFTSize();
355 case(1024): return 0; break;
356 case(2048): return 1; break;
357 case(4096): return 2; break;
358 case(8192): return 3; break;
359 case(16384): return 3; break;
360 case(32768): return 3; break;
366 SpectrumGUIClass::SetFFTSize(const int newSize)
368 //_windowStateLock->Lock();
370 //_windowStateLock->Unlock();
374 SpectrumGUIClass::GetLastGUIUpdateTime() const
376 timespec returnValue;
377 //_windowStateLock->Lock();
378 returnValue = _lastGUIUpdateTime;
379 //_windowStateLock->Unlock();
384 SpectrumGUIClass::SetLastGUIUpdateTime(const timespec newTime)
386 //_windowStateLock->Lock();
387 _lastGUIUpdateTime = newTime;
388 //_windowStateLock->Unlock();
392 SpectrumGUIClass::GetPendingGUIUpdateEvents() const
394 unsigned int returnValue = 0;
395 //_windowStateLock->Lock();
396 returnValue = _pendingGUIUpdateEventsCount;
397 //_windowStateLock->Unlock();
402 SpectrumGUIClass::IncrementPendingGUIUpdateEvents()
404 //_windowStateLock->Lock();
405 _pendingGUIUpdateEventsCount++;
406 //_windowStateLock->Unlock();
410 SpectrumGUIClass::DecrementPendingGUIUpdateEvents()
412 //_windowStateLock->Lock();
413 if(_pendingGUIUpdateEventsCount > 0){
414 _pendingGUIUpdateEventsCount--;
416 //_windowStateLock->Unlock();
420 SpectrumGUIClass::ResetPendingGUIUpdateEvents()
422 //_windowStateLock->Lock();
423 _pendingGUIUpdateEventsCount = 0;
424 //_windowStateLock->Unlock();
429 SpectrumGUIClass::qwidget()
431 return (QWidget*)_spectrumDisplayForm;
435 SpectrumGUIClass::SetTimeDomainAxis(double min, double max)
437 _spectrumDisplayForm->SetTimeDomainAxis(min, max);
441 SpectrumGUIClass::SetConstellationAxis(double xmin, double xmax,
442 double ymin, double ymax)
444 _spectrumDisplayForm->SetConstellationAxis(xmin, xmax, ymin, ymax);
449 SpectrumGUIClass::SetConstellationPenSize(int size){
450 _spectrumDisplayForm->SetConstellationPenSize(size);
455 SpectrumGUIClass::SetFrequencyAxis(double min, double max)
457 _spectrumDisplayForm->SetFrequencyAxis(min, max);
461 SpectrumGUIClass::SetUpdateTime(double t)
464 _spectrumDisplayForm->SetUpdateTime(_updateTime);
468 #endif /* SPECTRUM_GUI_CLASS_CPP */