7 #include <qapplication.h>
8 #include <omnithread.h>
11 #include <fftdisplay.h>
13 #warning Must make this threadsafe
14 static bool g_exit_flag = false;
16 void read_function(void* ptr){
18 fft_display* fftDisplay = (fft_display*)ptr;
20 std::vector<gr_complex> fftData(fftDisplay->get_fft_bin_size());
21 for(unsigned int number = 0; number < fftData.size(); number++){
22 fftData[number] = gr_complex(static_cast<float>(number), static_cast<float>(number));
25 float* readBuffer = new float[fftDisplay->get_fft_bin_size()*2];
28 fftDisplay->set_data(fftData);
31 // Read in the data here
33 std::cin.read((char*)readBuffer, fftDisplay->get_fft_bin_size()*sizeof(gr_complex));
34 amntRead = std::cin.gcount();
36 if(amntRead != static_cast<int>(fftDisplay->get_fft_bin_size()*sizeof(gr_complex))){
37 fprintf(stderr, "Invalid Read Amount from stdin - closing program\n");
42 for(unsigned int number = 0; number < fftData.size(); number++){
43 fftData[number] = gr_complex(readBuffer[2*number], readBuffer[(2*number)+1]);
46 fftDisplay->set_data(fftData);
48 fftDisplay->update_display();
50 qApp->wakeUpGuiThread();
57 int main (int argc, char* argv[]){
59 extern int optind, optopt;
60 float start_frequency = 0.0;
61 float stop_frequency = 4000.0;
63 unsigned int fft_bin_size = 1024;
65 while ((c = getopt(argc, argv, "s:p:b:")) != -1){
67 case 's': start_frequency = strtod(optarg, NULL); break;
68 case 'p': stop_frequency = strtod(optarg, NULL); break;
69 case 'b': fft_bin_size = (unsigned int)(atoi(optarg)); break;
70 case ':': /* -s or -p w/o operand */
71 fprintf(stderr, "Option -%c requires an arguement\n", optopt); break;
72 case '?': fprintf(stderr, "Unrecognized option: -%c\n", optopt);
73 fprintf(stderr, "Valid Arguements\n -s <start frequency>\n -p <stop frequency> -b <fft_bin_size> - number of fft samples per display\n");
78 // Verify the stop frequency is greater than the stop frequency
79 if(stop_frequency < start_frequency){
80 fprintf(stderr, "Stop Frequency (%0.0f Hz) was less than the Start Frequency (%0.0f Hz)\n", stop_frequency, start_frequency);
84 // Create the QApplication - this MUST be done before ANY QObjects are created
85 QApplication* qApp = new QApplication(argc, argv);
87 fft_display* fftDisplay = new fft_display(fft_bin_size); // No Parent Specified
90 fftDisplay->resize(640,240);
92 // Set the start and stop frequency
93 fftDisplay->set_start_frequency(start_frequency);
94 fftDisplay->set_stop_frequency(stop_frequency);
97 omni_thread* thread_ptr = new omni_thread(&read_function, (void*)fftDisplay);
99 // Set up the thread to read the data from stdin
103 // Make the closing of the last window call the quit()
104 QObject::connect(qApp, SIGNAL(lastWindowClosed()), qApp, SLOT(quit()));
106 // finally, refresh the plot
107 fftDisplay->update_display();
110 // Start the Event Thread
113 // No QObjects should be deleted once the event thread exits...
118 // Destroy the Event Thread