00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030 #include <stdio.h>
00031 #include <stdlib.h>
00032 #include <string.h>
00033 #include <strings.h>
00034 #include <netinet/in.h>
00035 #include <sys/types.h>
00036 #include <sys/socket.h>
00037 #include <arpa/inet.h>
00038 #include <ctype.h>
00039 #include <gtk/gtk.h>
00040 #include "PmuGui.h"
00041 #include "ServerFunction.h"
00042
00043
00044
00045
00046
00047
00048
00049
00050
00051
00052
00053
00054
00055
00056
00057
00058
00059
00060
00061
00062
00063
00064
00065
00066
00067 int isNumber(char *s)
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 };
00090
00091
00092
00093
00094
00095
00096
00097
00098 int checkip(char ip[])
00099 {
00100 struct sockaddr_in sa;
00101 int result = inet_pton(AF_INET, ip, &(sa.sin_addr));
00102
00103 return result;
00104 };
00105
00106
00107
00108
00109
00110
00111
00112 void destroy (GtkWidget *widget, gpointer udata)
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 };
00126
00127
00128
00129
00130
00131
00132
00133
00134 void destroy1 (GtkWidget *widget, gpointer udata)
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 };
00151
00152
00153
00154
00155
00156
00157
00158
00159 void about_pmu (GtkButton *widget, gpointer udata)
00160 {
00161
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
00166 about_dialog = gtk_about_dialog_new ();
00167
00168
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
00179 g_signal_connect_swapped (about_dialog, "response", G_CALLBACK (gtk_widget_destroy), about_dialog);
00180
00181
00182 gtk_widget_show_all (about_dialog);
00183 };
00184
00185
00186
00187
00188
00189
00190
00191
00192 void Pmu_Help (GtkButton *but, gpointer udata)
00193 {
00194 GtkWidget *help_dialog;
00195
00196
00197 help_dialog = gtk_about_dialog_new ();
00198
00199
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
00204 g_signal_connect_swapped (help_dialog, "response", G_CALLBACK (gtk_widget_destroy), help_dialog);
00205 gtk_widget_show_all (help_dialog);
00206 };
00207
00208
00209
00210
00211
00212
00213
00214 void validation_result (char *msg)
00215 {
00216 GtkWidget *val_dialog;
00217
00218
00219 val_dialog = gtk_about_dialog_new ();
00220
00221
00222 gtk_about_dialog_set_program_name ((GtkAboutDialog *)val_dialog, " ");
00223 gtk_about_dialog_set_comments ((GtkAboutDialog *)val_dialog, msg);
00224
00225
00226 g_signal_connect_swapped (val_dialog, "response", G_CALLBACK (gtk_widget_destroy), val_dialog);
00227
00228
00229 gtk_widget_show_all (val_dialog);
00230 };
00231
00232
00233
00234
00235
00236
00237
00238
00239 void pmu_colors()
00240 {
00241
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>");
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
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
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
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 };
00270
00271
00272
00273
00274
00275
00276
00277
00278
00279 int validation_pmu_server (GtkButton *button, gpointer udata)
00280 {
00281
00282 char *errmsg1, tmp[4];
00283 const char *text1, *text2;
00284 FILE *fp;
00285
00286 srvr_entry = 0;
00287
00288
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)))
00295 {
00296 errmsg1 = "\tPlease enter valid value for PMU Server Port\t\n";
00297 validation_result (errmsg1);
00298 return 0;
00299 }
00300 else
00301 {
00302 srvr_entry = 1;
00303
00304
00305 if((fp=fopen("PmuServer.txt", "wb"))==NULL)
00306 {
00307 printf("Cannot open file.\n");
00308 exit(1);
00309 }
00310
00311
00312 fputs(text1, fp);
00313 fputc(' ', fp);
00314 fputs(text2, fp);
00315 fclose(fp);
00316
00317
00318 gtk_widget_destroy(pmu_server_window);
00319
00320 errmsg1 = "\t\tPMU Server run Successfully\t\t\n";
00321 validation_result (errmsg1);
00322 return 1;
00323 }
00324 };
00325
00326
00327
00328
00329
00330
00331
00332 void pmu_server ()
00333 {
00334
00335 GtkWidget *table, *label;
00336 GtkWidget *valdbutton, *help_button;
00337
00338
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
00346 table = gtk_table_new (4, 2, FALSE);
00347
00348
00349 gtk_table_set_row_spacings (GTK_TABLE (table), 50);
00350 gtk_table_set_col_spacings (GTK_TABLE (table), 5);
00351
00352
00353 gtk_box_pack_start (GTK_BOX (GTK_DIALOG(pmu_server_window)->vbox), table, TRUE, TRUE, 0);
00354 gtk_widget_show (table);
00355
00356
00357 valdbutton = gtk_button_new_with_label ("Run");
00358 help_button = gtk_button_new_with_label ("Help");
00359
00360
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
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
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
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
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
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
00408 gtk_widget_show (pmu_server_window);
00409 validation_result ("\t\tPlease first enter the details for PMU setup.\t\t\n");
00410 };
00411
00412