#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>
#include <netinet/in.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <ctype.h>
#include <gtk/gtk.h>
#include "PmuGui.h"
#include "ServerFunction.h"
Go to the source code of this file.
Functions | |
int | isNumber (char *s) |
int | checkip (char ip[]) |
void | destroy (GtkWidget *widget, gpointer udata) |
void | destroy1 (GtkWidget *widget, gpointer udata) |
void | about_pmu (GtkButton *widget, gpointer udata) |
void | Pmu_Help (GtkButton *but, gpointer udata) |
void | validation_result (char *msg) |
void | pmu_colors () |
int | validation_pmu_server (GtkButton *button, gpointer udata) |
void | pmu_server () |
void about_pmu | ( | GtkButton * | widget, | |
gpointer | udata | |||
) |
Definition at line 159 of file PmuGui.c.
Referenced by main().
00160 { 00161 /* local variables */ 00162 GtkWidget *about_dialog; 00163 const gchar *auth[] = {"\nDr. A.M. Kulkarni <http://www.ee.iitb.ac.in/wiki/faculty/anil>", "\nProf. S.U. Ghumbre <shashi.comp@coep.ac.in>", "\nProf. V.Z. Attar <vahida.comp@coep.ac.in>", "\nNitesh Pandit <panditnitesh@gmail.com>", "\nKedar V. Khandeparkar <kedar.khandeparkar@gmail.com>", NULL}; 00164 00165 /* Create a about dialog for displaying about the iPDC. */ 00166 about_dialog = gtk_about_dialog_new (); 00167 00168 /* Define the diffrent properties of about_dialog. */ 00169 gtk_about_dialog_set_program_name ((GtkAboutDialog *)about_dialog, "\t\t\t\tiPDC 1.0\t\t\t\t"); 00170 gtk_about_dialog_set_comments ((GtkAboutDialog *)about_dialog, "A Phasor Data Concentrator for WAMS.\n\nUnder guidance of Dr. A.M. Kulkarni\nDepartment of Electrical Engineering\nIndian Institute of Technology, Bombay\nMumbai, INDIA\n\nAuthors: Kedar Khandeparkar\n Nitesh Pandit"); 00171 00172 gtk_about_dialog_set_license ((GtkAboutDialog *)about_dialog, "\t\t\t\tiPDC - A Phasor Data Concentrator\n\nGeneral Public License (GPL)\n\nAuthors:\n\t\tKedar V. Khandeparkar <kedar.khandeparkar@gmail.com>\n\t\tNitesh Pandit <panditnitesh@gmail.com>\n\n\nThis program is free software; you can redistribute it and/or\nmodify it under the terms of the GNU General Public License\nas published by the Free Software Foundation; either version 2\nof the License, or (at your option) any later version.\n\nThis program is distributed in the hope that it will be useful,\nbut WITHOUT ANY WARRANTY; without even the implied warranty of\nMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\nGNU General Public License for more details.\n\nYou should have received a copy of the GNU General Public License\nalong with this program; if not, write to the Free Software\nFoundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.\n"); 00173 00174 gtk_about_dialog_set_copyright ((GtkAboutDialog *)about_dialog, "Copyright (C) 2010-2011 GPL-3.0"); 00175 gtk_about_dialog_set_website ((GtkAboutDialog *)about_dialog, "http://wafms.co.cc/ipdc/"); 00176 gtk_about_dialog_set_authors ((GtkAboutDialog *)about_dialog, auth); 00177 00178 /* Ensure that the dialog box is destroyed when the user responds */ 00179 g_signal_connect_swapped (about_dialog, "response", G_CALLBACK (gtk_widget_destroy), about_dialog); 00180 00181 /* Finally show the about_dialog. */ 00182 gtk_widget_show_all (about_dialog); 00183 };
int checkip | ( | char | ip[] | ) |
void destroy | ( | GtkWidget * | widget, | |
gpointer | udata | |||
) |
Definition at line 112 of file PmuGui.c.
References pid.
Referenced by main().
00113 { 00114 g_print ("\nPMU Simulator Closing....!!!\n"); 00115 if(!kill(pid, SIGKILL)) 00116 { 00117 printf("Sent a SIGKILL signal to Process ID %d\n",pid); 00118 } 00119 else 00120 { 00121 printf("Signal not sent to %d\n",pid); 00122 } 00123 gtk_main_quit(); 00124 exit(1); 00125 };
void destroy1 | ( | GtkWidget * | widget, | |
gpointer | udata | |||
) |
Definition at line 134 of file PmuGui.c.
References pid, and srvr_entry.
Referenced by pmu_server().
00135 { 00136 if (srvr_entry == 0) 00137 { 00138 g_print ("\nPMU Simulator Closing....!!!\n"); 00139 if(!kill(pid, SIGKILL)) 00140 { 00141 printf("Sent a SIGKILL signal to Process ID %d\n",pid); 00142 } 00143 else 00144 { 00145 printf("Signal not sent to %d\n",pid); 00146 } 00147 gtk_main_quit(); 00148 exit(1); 00149 } 00150 };
int isNumber | ( | char * | s | ) |
Definition at line 67 of file PmuGui.c.
Referenced by validation_cfg_create(), validation_new_data_rate(), validation_ph_an_num(), validation_pmu_server(), and validation_remove_ph_an_num().
00068 { 00069 int dot=0, num=0, end=0; 00070 00071 while(isspace(*s))s++; 00072 if(*s == '-')s++; 00073 if(! *s)return 0; 00074 while(*s) 00075 if(isspace(*s)) 00076 end=1, s++; 00077 else if(end) 00078 return 0; 00079 else if(isdigit(*s)) 00080 num=1, s++; 00081 else if(*s=='.') 00082 if(dot) 00083 return 0; 00084 else 00085 dot=1,s++; 00086 else 00087 return 0; 00088 return num; 00089 };
void pmu_colors | ( | ) |
Definition at line 239 of file PmuGui.c.
References _pmuStruct::admin_label, _pmuStruct::footer_label, _pmuStruct::img_label, _pmuStruct::logo_butun, markup, pmu_data, and _pmuStruct::welcome_pmu.
Referenced by main().
00240 { 00241 /* Set the font and color for the heading on 'welcome_pmu' lable */ 00242 markup = g_markup_printf_escaped ("<span foreground=\"#006666\" font='16'><b>Phasor Measurement Unit\n\t PMU Simulator</b></span>"); 00243 gtk_label_set_markup (GTK_LABEL (pmu_data->welcome_pmu), markup); 00244 g_free (markup); 00245 00246 markup = g_markup_printf_escaped ("<span foreground=\"#330000\" font='10'><b>\n-------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------</b>\n\n\t\t\t\t\t\t\t\t\t\t\t\t\tAll Rights Reserved\n</span>");//\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<b>Indian Institute of Technology, Bombay</b></span>"); 00247 gtk_label_set_markup (GTK_LABEL (pmu_data->footer_label), markup); 00248 g_free (markup); 00249 00250 markup = g_markup_printf_escaped ("<span foreground=\"#333333\" font='10'><b>Admin Operations</b></span>"); 00251 gtk_label_set_markup (GTK_LABEL (pmu_data->admin_label), markup); 00252 g_free (markup); 00253 00254 /* Add a "close" button to the bottom of the dialog */ 00255 GdkColor color; 00256 GtkWidget *image, *image1; 00257 gdk_color_parse( "#999999", &color ); 00258 gtk_widget_modify_bg( GTK_WIDGET(pmu_data->img_label), GTK_STATE_NORMAL, &color ); 00259 00260 /* Set the general image on a button */ 00261 image = gtk_image_new_from_file("PSLab.PNG"); 00262 gtk_button_set_image ((GtkButton *)pmu_data->img_label, image); 00263 gtk_widget_show (pmu_data->img_label); 00264 00265 /* Set the image (PMU-logo) on a specific button */ 00266 image1 = gtk_image_new_from_file("PmuLogo.png"); 00267 gtk_button_set_image ((GtkButton *)pmu_data->logo_butun, image1); 00268 gtk_widget_show (pmu_data->logo_butun); 00269 };
void Pmu_Help | ( | GtkButton * | but, | |
gpointer | udata | |||
) |
Definition at line 192 of file PmuGui.c.
Referenced by cfg_create_function(), and pmu_server().
00193 { 00194 GtkWidget *help_dialog; 00195 00196 /* Create the widgets */ 00197 help_dialog = gtk_about_dialog_new (); 00198 00199 //GtkWidget *image1 = gtk_image_new_from_file("pdcIMG.jpg"); 00200 gtk_about_dialog_set_program_name ((GtkAboutDialog *)help_dialog, "PMU HELP\n\n"); 00201 gtk_about_dialog_set_comments ((GtkAboutDialog *)help_dialog, "1) ID Code ex. 50, 60, etc.\t\t\t\t\t\t\n\n 2) Port should be greater than 1500 and less than 65535.\n\n3) Channel Name should be less than 16 characters.\t\n\n4) Fixed/Floating point and Rectangular/Polar are the\nrepresentation of measured values.\n\n"); 00202 00203 /* Ensure that the dialog box is destroyed when the user responds */ 00204 g_signal_connect_swapped (help_dialog, "response", G_CALLBACK (gtk_widget_destroy), help_dialog); 00205 gtk_widget_show_all (help_dialog); 00206 };
void pmu_server | ( | ) |
Definition at line 332 of file PmuGui.c.
References destroy1(), markup, p_port, p_protocol, Pmu_Help(), pmu_server_window, validation_pmu_server(), and validation_result().
Referenced by main().
00333 { 00334 /* local variables */ 00335 GtkWidget *table, *label; 00336 GtkWidget *valdbutton, *help_button; 00337 00338 /* Create a new dialog window for PMU Server Setup */ 00339 pmu_server_window = gtk_dialog_new (); 00340 g_signal_connect (pmu_server_window, "destroy", G_CALLBACK (gtk_widget_destroy), pmu_server_window); 00341 gtk_window_set_title (GTK_WINDOW (pmu_server_window), "PMU Server Setup"); 00342 gtk_container_set_border_width (GTK_CONTAINER (pmu_server_window), 10); 00343 gtk_widget_set_size_request (pmu_server_window, 350, 300); 00344 00345 /* Create a table of 4 by 2 squares. */ 00346 table = gtk_table_new (4, 2, FALSE); 00347 00348 /* Set the spacing to 50 on x and 5 on y */ 00349 gtk_table_set_row_spacings (GTK_TABLE (table), 50); 00350 gtk_table_set_col_spacings (GTK_TABLE (table), 5); 00351 00352 /* Pack the table into the window */ 00353 gtk_box_pack_start (GTK_BOX (GTK_DIALOG(pmu_server_window)->vbox), table, TRUE, TRUE, 0); 00354 gtk_widget_show (table); 00355 00356 /* Add few buttons to the bottom of the dialog */ 00357 valdbutton = gtk_button_new_with_label ("Run"); 00358 help_button = gtk_button_new_with_label ("Help"); 00359 00360 /* This simply creates a grid of toggle buttons on the table */ 00361 label = gtk_label_new (" "); 00362 markup = g_markup_printf_escaped ("<span foreground=\"#990033\" font='12'><b>Enter PMU Server Details</b></span>"); 00363 gtk_label_set_markup (GTK_LABEL (label), markup); 00364 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 2, 0, 1); 00365 gtk_widget_show (label); 00366 g_free (markup); 00367 00368 label = gtk_label_new ("Server Port"); 00369 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 2, 3); 00370 gtk_widget_show (label); 00371 00372 label = gtk_label_new ("Protocol "); 00373 gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 3, 4); 00374 gtk_widget_show (label); 00375 00376 /* Create text boxes for user to enter appropriate values */ 00377 p_port = gtk_entry_new(); 00378 gtk_entry_set_max_length ((GtkEntry *)p_port, 5); 00379 gtk_table_attach_defaults (GTK_TABLE (table), p_port, 1, 2, 2, 3); 00380 gtk_widget_show (p_port); 00381 00382 /* Create combo boxe for user with some fixed values */ 00383 p_protocol = gtk_combo_box_new_text(); 00384 gtk_combo_box_append_text(GTK_COMBO_BOX(p_protocol), "UDP"); 00385 gtk_combo_box_append_text(GTK_COMBO_BOX(p_protocol), "TCP"); 00386 gtk_combo_box_set_active(GTK_COMBO_BOX(p_protocol), 0); 00387 gtk_table_attach_defaults (GTK_TABLE (table), p_protocol, 1, 2, 3, 4); 00388 gtk_widget_show (p_protocol); 00389 00390 /* Signal handling for buttons on PMU Server Setup Window */ 00391 g_signal_connect_swapped (valdbutton, "clicked", G_CALLBACK (validation_pmu_server), valdbutton); 00392 g_signal_connect_swapped (help_button, "clicked", G_CALLBACK (Pmu_Help), NULL); 00393 g_signal_connect (pmu_server_window, "destroy", G_CALLBACK(destroy1), NULL); 00394 00395 /* This makes it so the button is the default. */ 00396 gtk_widget_set_can_default (valdbutton, TRUE); 00397 gtk_widget_set_can_default (help_button, TRUE); 00398 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (pmu_server_window)->action_area), valdbutton, TRUE, TRUE, 0); 00399 gtk_box_pack_start (GTK_BOX (GTK_DIALOG (pmu_server_window)->action_area), help_button, TRUE, TRUE, 0); 00400 00401 /* This grabs this button to be the default button. Simply hitting the "Enter" key will cause this button to activate. */ 00402 gtk_widget_grab_default (valdbutton); 00403 gtk_widget_show (valdbutton); 00404 gtk_widget_grab_default (help_button); 00405 gtk_widget_show (help_button); 00406 00407 /* Finally show the pmu_server_window */ 00408 gtk_widget_show (pmu_server_window); 00409 validation_result ("\t\tPlease first enter the details for PMU setup.\t\t\n"); /* Show the popup window to user */ 00410 };
int validation_pmu_server | ( | GtkButton * | button, | |
gpointer | udata | |||
) |
Definition at line 279 of file PmuGui.c.
References isNumber(), p_port, p_protocol, pmu_server_window, srvr_entry, and validation_result().
Referenced by pmu_server().
00280 { 00281 /* local variables */ 00282 char *errmsg1, tmp[4]; 00283 const char *text1, *text2; 00284 FILE *fp; 00285 00286 srvr_entry = 0; 00287 00288 /* Get the text entries filled by user */ 00289 text1 = gtk_entry_get_text(GTK_ENTRY(p_port)); 00290 text2 = gtk_combo_box_get_active_text(GTK_COMBO_BOX(p_protocol)); 00291 memset(tmp,'\0',4); 00292 strcpy (tmp, text2); 00293 00294 if(!isNumber((char *)text1) && (atoi(text1) < 1500 || (atoi(text1) > 65535))) /* Check for valid port number */ 00295 { 00296 errmsg1 = "\tPlease enter valid value for PMU Server Port\t\n"; 00297 validation_result (errmsg1); /* Show the unsuccess message to user */ 00298 return 0; 00299 } 00300 else 00301 { 00302 srvr_entry = 1; 00303 00304 /* Open the file "PmuServer.txt" in write mode */ 00305 if((fp=fopen("PmuServer.txt", "wb"))==NULL) 00306 { 00307 printf("Cannot open file.\n"); 00308 exit(1); 00309 } 00310 00311 /* Write the information entered by user */ 00312 fputs(text1, fp); 00313 fputc(' ', fp); 00314 fputs(text2, fp); 00315 fclose(fp); 00316 00317 /* Close/destroy the pmu_server_window */ 00318 gtk_widget_destroy(pmu_server_window); 00319 00320 errmsg1 = "\t\tPMU Server run Successfully\t\t\n"; 00321 validation_result (errmsg1); /* Show the success message to user */ 00322 return 1; 00323 } 00324 };
void validation_result | ( | char * | msg | ) |
Definition at line 214 of file PmuGui.c.
Referenced by cfg_STAT_change(), create_cfg(), final_cfg_create(), header_frm_gen(), pmu_server(), reconfig_cfg_CC(), validation_analog_names(), validation_cfg_create(), validation_digital_names(), validation_hdr_frm(), validation_new_analog_names(), validation_new_data_rate(), validation_new_phasor_names(), validation_ph_an_num(), validation_phasor_names(), validation_pmu_server(), and validation_remove_ph_an_num().
00215 { 00216 GtkWidget *val_dialog; 00217 00218 /* Create the widgets a new dialog box */ 00219 val_dialog = gtk_about_dialog_new (); 00220 00221 /* Define the diffrent properties of val_dialog. */ 00222 gtk_about_dialog_set_program_name ((GtkAboutDialog *)val_dialog, " "); 00223 gtk_about_dialog_set_comments ((GtkAboutDialog *)val_dialog, msg); 00224 00225 /* Ensure that the dialog box is destroyed when the user responds */ 00226 g_signal_connect_swapped (val_dialog, "response", G_CALLBACK (gtk_widget_destroy), val_dialog); 00227 00228 /* Finally show the val_dialog. */ 00229 gtk_widget_show_all (val_dialog); 00230 };