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 newStartFrequency,
15 const double newStopFrequency)
17 _dataPoints = maxDataSize;
21 _lastDataPointCount = _dataPoints;
25 _pendingGUIUpdateEventsCount = 0;
26 _droppedEntriesCount = 0;
29 _startFrequency = newStartFrequency;
30 _stopFrequency = newStopFrequency;
32 #warning SPECIFY THIS LATER...
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)
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(parent);
86 // Toggle Windows on/off
87 _spectrumDisplayForm->ToggleTabFrequency(frequency);
88 _spectrumDisplayForm->ToggleTabWaterfall(waterfall);
89 _spectrumDisplayForm->ToggleTabWaterfall3D(waterfall3d);
90 _spectrumDisplayForm->ToggleTabTime(time);
91 _spectrumDisplayForm->ToggleTabConstellation(constellation);
93 _windowOpennedFlag = true;
95 _spectrumDisplayForm->setSystem(this, _dataPoints, _fftSize);
97 qApp->processEvents();
100 //_windowStateLock->Unlock();
102 SetDisplayTitle(_title);
105 qApp->postEvent(_spectrumDisplayForm,
106 new QEvent(QEvent::Type(QEvent::User+3)));
108 qApp->processEvents();
110 timespec_reset(&_lastGUIUpdateTime);
112 // Draw Blank Display
113 UpdateWindow(false, NULL, 0, NULL, 0, NULL, 0, 1.0, get_highres_clock(), true);
116 qApp->processEvents();
120 SpectrumGUIClass::Reset()
122 if(GetWindowOpenFlag()) {
123 qApp->postEvent(_spectrumDisplayForm,
124 new SpectrumFrequencyRangeEvent(_centerFrequency,
127 qApp->postEvent(_spectrumDisplayForm, new SpectrumWindowResetEvent());
129 _droppedEntriesCount = 0;
130 // Call the following function the the Spectrum Window Reset Event window
131 // ResetPendingGUIUpdateEvents();
135 SpectrumGUIClass::SetDisplayTitle(const std::string newString)
137 _title.assign(newString);
139 if(GetWindowOpenFlag()){
140 qApp->postEvent(_spectrumDisplayForm,
141 new SpectrumWindowCaptionEvent(_title.c_str()));
146 SpectrumGUIClass::GetWindowOpenFlag()
148 bool returnFlag = false;
149 //_windowStateLock->Lock();
150 returnFlag = _windowOpennedFlag;
151 //_windowStateLock->Unlock();
157 SpectrumGUIClass::SetWindowOpenFlag(const bool newFlag)
159 //_windowStateLock->Lock();
160 _windowOpennedFlag = newFlag;
161 //_windowStateLock->Unlock();
165 SpectrumGUIClass::SetFrequencyRange(const double centerFreq,
166 const double startFreq,
167 const double stopFreq)
169 //_windowStateLock->Lock();
170 _centerFrequency = centerFreq;
171 _startFrequency = startFreq;
172 _stopFrequency = stopFreq;
174 _spectrumDisplayForm->SetFrequencyRange(_centerFrequency,
177 //_windowStateLock->Unlock();
181 SpectrumGUIClass::GetStartFrequency() const
183 double returnValue = 0.0;
184 //_windowStateLock->Lock();
185 returnValue = _startFrequency;
186 //_windowStateLock->Unlock();
191 SpectrumGUIClass::GetStopFrequency() const
193 double returnValue = 0.0;
194 //_windowStateLock->Lock();
195 returnValue = _stopFrequency;
196 //_windowStateLock->Unlock();
201 SpectrumGUIClass::GetCenterFrequency() const
203 double returnValue = 0.0;
204 //_windowStateLock->Lock();
205 returnValue = _centerFrequency;
206 //_windowStateLock->Unlock();
212 SpectrumGUIClass::UpdateWindow(const bool updateDisplayFlag,
213 const std::complex<float>* fftBuffer,
214 const uint64_t inputBufferSize,
215 const float* realTimeDomainData,
216 const uint64_t realTimeDomainDataSize,
217 const float* complexTimeDomainData,
218 const uint64_t complexTimeDomainDataSize,
219 const double timePerFFT,
220 const timespec timestamp,
221 const bool lastOfMultipleFFTUpdateFlag)
223 int64_t bufferSize = inputBufferSize;
224 bool repeatDataFlag = false;
225 if(bufferSize > _dataPoints){
226 bufferSize = _dataPoints;
228 int64_t timeDomainBufferSize = 0;
230 if(updateDisplayFlag){
231 if((fftBuffer != NULL) && (bufferSize > 0)){
232 memcpy(_fftPoints, fftBuffer, bufferSize * sizeof(std::complex<float>));
235 // Can't do a memcpy since ths is going from float to double data type
236 if((realTimeDomainData != NULL) && (realTimeDomainDataSize > 0)){
237 const float* realTimeDomainDataPtr = realTimeDomainData;
239 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
240 timeDomainBufferSize = realTimeDomainDataSize;
242 memset( _imagTimeDomainPoints, 0x0, realTimeDomainDataSize*sizeof(double));
243 for( uint64_t number = 0; number < realTimeDomainDataSize; number++){
244 *realTimeDomainPointsPtr++ = *realTimeDomainDataPtr++;
248 // Can't do a memcpy since ths is going from float to double data type
249 if((complexTimeDomainData != NULL) && (complexTimeDomainDataSize > 0)){
250 const float* complexTimeDomainDataPtr = complexTimeDomainData;
252 double* realTimeDomainPointsPtr = _realTimeDomainPoints;
253 double* imagTimeDomainPointsPtr = _imagTimeDomainPoints;
255 timeDomainBufferSize = complexTimeDomainDataSize;
256 for( uint64_t number = 0; number < complexTimeDomainDataSize; number++){
257 *realTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
258 *imagTimeDomainPointsPtr++ = *complexTimeDomainDataPtr++;
263 // If bufferSize is zero, then just update the display by sending over the old data
265 bufferSize = _lastDataPointCount;
266 repeatDataFlag = true;
269 // Since there is data this time, update the count
270 _lastDataPointCount = bufferSize;
273 const timespec currentTime = get_highres_clock();
274 const timespec lastUpdateGUITime = GetLastGUIUpdateTime();
276 if((diff_timespec(currentTime, lastUpdateGUITime) > (4*timePerFFT)) &&
277 (GetPendingGUIUpdateEvents() > 0) && !timespec_empty(&lastUpdateGUITime)) {
278 // Do not update the display if too much data is pending to be displayed
279 _droppedEntriesCount++;
283 IncrementPendingGUIUpdateEvents();
284 qApp->postEvent(_spectrumDisplayForm,
285 new SpectrumUpdateEvent(_fftPoints, bufferSize,
286 _realTimeDomainPoints,
287 _imagTimeDomainPoints,
288 timeDomainBufferSize,
289 timePerFFT, timestamp,
291 lastOfMultipleFFTUpdateFlag,
293 _droppedEntriesCount));
295 // Only reset the dropped entries counter if this is not
296 // repeat data since repeat data is dropped by the display systems
298 _droppedEntriesCount = 0;
304 SpectrumGUIClass::GetPowerValue() const
306 float returnValue = 0;
307 //_windowStateLock->Lock();
308 returnValue = _powerValue;
309 //_windowStateLock->Unlock();
314 SpectrumGUIClass::SetPowerValue(const float value)
316 //_windowStateLock->Lock();
318 //_windowStateLock->Unlock();
322 SpectrumGUIClass::GetWindowType() const
325 //_windowStateLock->Lock();
326 returnValue = _windowType;
327 //_windowStateLock->Unlock();
332 SpectrumGUIClass::SetWindowType(const int newType)
334 //_windowStateLock->Lock();
335 _windowType = newType;
336 //_windowStateLock->Unlock();
340 SpectrumGUIClass::GetFFTSize() const
343 //_windowStateLock->Lock();
344 returnValue = _fftSize;
345 //_windowStateLock->Unlock();
350 SpectrumGUIClass::GetFFTSizeIndex() const
352 int fftsize = GetFFTSize();
354 case(1024): return 0; break;
355 case(2048): return 1; break;
356 case(4096): return 2; break;
357 case(8192): return 3; break;
358 case(16384): return 3; break;
359 case(32768): return 3; break;
365 SpectrumGUIClass::SetFFTSize(const int newSize)
367 //_windowStateLock->Lock();
369 //_windowStateLock->Unlock();
373 SpectrumGUIClass::GetLastGUIUpdateTime() const
375 timespec returnValue;
376 //_windowStateLock->Lock();
377 returnValue = _lastGUIUpdateTime;
378 //_windowStateLock->Unlock();
383 SpectrumGUIClass::SetLastGUIUpdateTime(const timespec newTime)
385 //_windowStateLock->Lock();
386 _lastGUIUpdateTime = newTime;
387 //_windowStateLock->Unlock();
391 SpectrumGUIClass::GetPendingGUIUpdateEvents() const
393 unsigned int returnValue = 0;
394 //_windowStateLock->Lock();
395 returnValue = _pendingGUIUpdateEventsCount;
396 //_windowStateLock->Unlock();
401 SpectrumGUIClass::IncrementPendingGUIUpdateEvents()
403 //_windowStateLock->Lock();
404 _pendingGUIUpdateEventsCount++;
405 //_windowStateLock->Unlock();
409 SpectrumGUIClass::DecrementPendingGUIUpdateEvents()
411 //_windowStateLock->Lock();
412 if(_pendingGUIUpdateEventsCount > 0){
413 _pendingGUIUpdateEventsCount--;
415 //_windowStateLock->Unlock();
419 SpectrumGUIClass::ResetPendingGUIUpdateEvents()
421 //_windowStateLock->Lock();
422 _pendingGUIUpdateEventsCount = 0;
423 //_windowStateLock->Unlock();
428 SpectrumGUIClass::qwidget()
430 return (QWidget*)_spectrumDisplayForm;
434 #endif /* SPECTRUM_GUI_CLASS_CPP */