diff --git a/ClassDigitizer2Gen.cpp b/ClassDigitizer2Gen.cpp index d6bc60e..bf0d0f7 100644 --- a/ClassDigitizer2Gen.cpp +++ b/ClassDigitizer2Gen.cpp @@ -77,7 +77,7 @@ std::string Digitizer2Gen::GetPath(uint64_t handle){ } //########################################### Read Write -std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose = false){ +std::string Digitizer2Gen::ReadValue(const char * parameter, bool verbose){ if( !isConnected ) return "not connected"; //printf(" %s|%s \n", __func__, parameter); ret = CAEN_FELib_GetValue(handle, parameter, retValue); diff --git a/ClassDigitizer2Gen.h b/ClassDigitizer2Gen.h index 33bc937..58ebfd0 100644 --- a/ClassDigitizer2Gen.h +++ b/ClassDigitizer2Gen.h @@ -62,9 +62,10 @@ class Digitizer2Gen { ~Digitizer2Gen(); int OpenDigitizer(const char * url); + bool IsConnected() const {return isConnected;} int CloseDigitizer(); - std::string ReadValue(const char * parameter, bool verbose); + std::string ReadValue(const char * parameter, bool verbose = false); void WriteValue(const char * parameter, std::string value); void SendCommand(const char * parameter); @@ -76,7 +77,7 @@ class Digitizer2Gen { void StartACQ(); void StopACQ(); - bool IsAcqOn() {return acqON;} + bool IsAcqOn() const {return acqON;} void SetPHADataFormat(unsigned short dataFormat); // 0 = all data, // 1 = analog trace-0 only + flags @@ -91,15 +92,16 @@ class Digitizer2Gen { void ProgramPHA(bool testPulse = false); void ReadDigitizerSettings(); - unsigned short GetNChannels() {return nChannels;} - unsigned short GetCh2ns() {return ch2ns;} - uint64_t GetHandle() {return handle;} + unsigned short GetNChannels() const {return nChannels;} + unsigned short GetCh2ns() const {return ch2ns;} + uint64_t GetHandle() const {return handle;} Event *evt; // should be evt[MaxNumber], when full or stopACQ, save into file void OpenOutFile(std::string fileName); void CloseOutFile(); void SaveDataToFile(); + }; #endif diff --git a/SOLARISDAQ.cpp b/SOLARISDAQ.cpp index dcae95e..6f9dcdd 100644 --- a/SOLARISDAQ.cpp +++ b/SOLARISDAQ.cpp @@ -1,24 +1,142 @@ -#include +#include +#include -static void print_hello (GtkWidget *widget, gpointer data){ - g_print ("Hello World\n"); +#include +#include "ClassDigitizer2Gen.h" +#include "influxdb.h" + +std::mutex digiMTX; +Digitizer2Gen * digi = NULL; // new Digitizer2Gen(); +unsigned short nDigi = 0; +InfluxDB * influx = NULL; // new InfluxDB("https://fsunuc.physics.fsu.edu/influx/", false); + +GtkTextBuffer * logBuffer = NULL; +GtkWidget * notebook = NULL; +GtkWidget * bnOpenDigis = NULL; + +static void OpenDigitizers(){ + + digi = new Digitizer2Gen(); + digi->OpenDigitizer("dig2://192.168.0.100/"); + //digi->Reset(); + + if( digi->IsConnected() ){ + gtk_text_buffer_set_text(logBuffer, ("A digitizer " + digi->ReadValue("/par/SerialNum") + " is opened.").c_str(), -1); + + GtkWidget * box = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); // 2nd arg is the spacing + gtk_widget_set_halign(box, GTK_ALIGN_CENTER); + gtk_widget_set_valign(box, GTK_ALIGN_CENTER); + gtk_box_set_homogeneous(GTK_BOX (box), true); + + gtk_notebook_append_page( GTK_NOTEBOOK(notebook), box, gtk_label_new( ("Digi-" + digi->ReadValue("/par/SerialNum") ).c_str() ) ) ; + + GtkWidget * v1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); gtk_box_append( GTK_BOX(box), v1); + + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("IP: " + digi->ReadValue("/par/IPAddress")).c_str())); + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("Model name: " + digi->ReadValue("/par/ModelName")).c_str())); + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("Firmware version: " + digi->ReadValue("/par/cupver")).c_str())); + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("DPPType: " + digi->ReadValue("/par/FwType")).c_str())); + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("DPP version: " + digi->ReadValue("/par/FPGA_FwVer")).c_str())); + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("ADC bits: " + digi->ReadValue("/par/ADC_Nbit")).c_str())); + gtk_box_append(GTK_BOX(v1), gtk_label_new( ("ADC rate: " + digi->ReadValue("/par/ADC_SamplRate") + " Msps, ch2ns: " + std::to_string(digi->GetCh2ns()) + " ns").c_str())); + + unsigned short nCh = digi->GetNChannels(); + + nDigi ++; + + } } -static void activate (GtkApplication *app, gpointer user_data){ +static void CloseDigitizers(){ + + if( digi != NULL){ + digi->CloseDigitizer(); + delete digi; + digi = NULL; + gtk_notebook_remove_page(GTK_NOTEBOOK(notebook), nDigi); + }else{ + gtk_text_buffer_set_text(logBuffer, "No digitizer is opened.", -1); + } + +} + +static void ProgramSetting(){ + + GtkWidget * window = gtk_window_new(); + gtk_window_set_title( GTK_WINDOW(window), "Program Setting"); + gtk_window_set_default_size( GTK_WINDOW(window), 600, 500); // w, h + + gtk_widget_show(window); +} + + +static void MainWindow (GtkApplication *app){ GtkWidget * window = gtk_application_window_new(app); gtk_window_set_title( GTK_WINDOW(window), "SOLARIS DAQ"); - gtk_window_set_default_size( GTK_WINDOW(window), 300, 200); // w, h + gtk_window_set_default_size( GTK_WINDOW(window), 600, 600); // w, h - GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0); - gtk_widget_set_halign(box, GTK_ALIGN_CENTER); - gtk_widget_set_valign(box, GTK_ALIGN_CENTER); - gtk_window_set_child( GTK_WINDOW(window), box); + //=========== Tabs + notebook = gtk_notebook_new(); + gtk_window_set_child( GTK_WINDOW(window), notebook); - GtkWidget * button = gtk_button_new_with_label("Hello World"); - g_signal_connect( button, "clicked", G_CALLBACK(print_hello), NULL); - g_signal_connect_swapped( button, "clicked", G_CALLBACK(gtk_window_destroy), window); - gtk_box_append( GTK_BOX(box), button); + //=========== Main Tab + GtkWidget * box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 5); // 2nd arg is the spacing + //gtk_widget_set_halign(box, GTK_ALIGN_CENTER); + //gtk_widget_set_valign(box, GTK_ALIGN_CENTER); + //gtk_box_set_homogeneous(GTK_BOX (box), true); + gtk_notebook_append_page( GTK_NOTEBOOK(notebook), box, gtk_label_new("Main")); + + { + GtkWidget * box2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); + gtk_widget_set_halign(box, GTK_ALIGN_CENTER); + gtk_widget_set_valign(box, GTK_ALIGN_CENTER); + gtk_box_set_homogeneous(GTK_BOX (box2), true); + gtk_box_append( GTK_BOX(box), box2); + + + GtkWidget * bnProgramSettings = gtk_button_new_with_label("Program Settings"); + g_signal_connect( bnProgramSettings, "clicked", G_CALLBACK(ProgramSetting), NULL); + gtk_box_append( GTK_BOX(box2), bnProgramSettings); + + GtkWidget * bnOpenDigis = gtk_button_new_with_label("Open Digitizers"); + g_signal_connect( bnOpenDigis, "clicked", G_CALLBACK(OpenDigitizers), NULL); + gtk_box_append( GTK_BOX(box2), bnOpenDigis); + + GtkWidget * bnCloseDigis = gtk_button_new_with_label("Close Digitizers"); + g_signal_connect( bnCloseDigis, "clicked", G_CALLBACK(CloseDigitizers), NULL); + gtk_box_append( GTK_BOX(box2), bnCloseDigis); + } + + + { + GtkWidget * box3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 5); + gtk_widget_set_halign(box, GTK_ALIGN_CENTER); + gtk_widget_set_valign(box, GTK_ALIGN_CENTER); + gtk_box_set_homogeneous(GTK_BOX (box3), true); + gtk_box_append( GTK_BOX(box), box3); + + GtkWidget * bnStart = gtk_button_new_with_label("Start Run"); + //g_signal_connect( bnStart, "clicked", G_CALLBACK(OpenDigitizers), NULL); + gtk_box_append( GTK_BOX(box3), bnStart); + + GtkWidget * bnEnd = gtk_button_new_with_label("End Run"); + //g_signal_connect( bnEnd, "clicked", G_CALLBACK(OpenDigitizers), NULL); + gtk_box_append( GTK_BOX(box3), bnEnd); + + GtkWidget * cbRunNum = gtk_combo_box_new(); + gtk_box_append( GTK_BOX(box3), cbRunNum); + + } + + + GtkWidget * logBox = gtk_scrolled_window_new (); + gtk_box_append( GTK_BOX(box), logBox); + + GtkWidget * logTextView = gtk_text_view_new(); + logBuffer = gtk_text_view_get_buffer( GTK_TEXT_VIEW(logTextView)); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (logTextView), GTK_WRAP_WORD_CHAR); + gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (logBox), logTextView); gtk_widget_show(window); } @@ -26,9 +144,14 @@ static void activate (GtkApplication *app, gpointer user_data){ int main (int argc, char **argv){ GtkApplication * app = gtk_application_new("example.example", G_APPLICATION_FLAGS_NONE); - g_signal_connect( app, "activate", G_CALLBACK(activate), NULL); + g_signal_connect( app, "activate", G_CALLBACK(MainWindow), NULL); int status = g_application_run( G_APPLICATION(app), argc, argv); g_object_unref( app); + //=================== clear memory + delete digi; + delete influx; + printf("============= GoodBye! ============\n"); + return status; }