diff --git a/iPDC/assets/utility_tools.ui b/iPDC/assets/utility_tools.ui index 153d59a..2989aee 100644 --- a/iPDC/assets/utility_tools.ui +++ b/iPDC/assets/utility_tools.ui @@ -3,7 +3,7 @@ - 800 + 900 700 False @@ -409,7 +409,39 @@ - + + + True + False + + + True + True + True + rgb(119,118,123) + + + 0 + 0 + + + + + True + False + No data + + + 1 + 0 + + + + + False + True + 3 + diff --git a/iPDC/assets/utility_tools.ui~ b/iPDC/assets/utility_tools.ui~ index 3dba50e..94ca09a 100644 --- a/iPDC/assets/utility_tools.ui~ +++ b/iPDC/assets/utility_tools.ui~ @@ -4,7 +4,7 @@ 800 - 600 + 700 False @@ -169,7 +169,7 @@ - + 100 80 @@ -179,7 +179,7 @@ 10 6 - + 80 True @@ -187,7 +187,7 @@ 35 - Voltage + Voltage Magnitude True True True @@ -218,7 +218,7 @@ 0 - 2 + 3 @@ -227,13 +227,14 @@ False 0 - kmeans - simple + Gaussian + kmeans + DTW 0 - 3 + 5 @@ -243,15 +244,52 @@ 0 frequency only - frequency,voltage - voltage + voltage only + frequency,voltage + + 0 + 7 + + + + + dfreq + True + True + True + + + 0 + 2 + + + + + True + False + Algorithm + 0 4 + + + True + False + Dimmensions + + + 0 + 6 + + + + + 0 @@ -271,22 +309,243 @@ - + + 150 + True + False + + + 1 + 1 + - + + True + False + vertical + + + True + False + Legend + True + + + False + True + 0 + + + + + + True + False + + + True + True + True + red + rgb(238,29,0) + + + 0 + 0 + + + + + True + False + Attack/Event + + + 1 + 0 + + + + + False + True + 1 + + + + + + True + False + + + True + True + True + rgb(0,255,0) + + + 0 + 0 + + + + + True + False + Normal + + + 1 + 0 + + + + + False + True + 2 + + + + + + True + False + + + True + True + True + rgb(119,118,123) + + + 0 + 0 + + + + + True + False + No data + + + 1 + 0 + + + + + False + True + 3 + + + + + + + + 2 + 0 + - - - - - - - - - - + + True + True + in + + + True + False + + + True + False + vertical + + + True + False + Graph Legend + + + False + True + 0 + + + + + + True + False + + + True + True + True + rgb(255,120,0) + + + 0 + 0 + + + + + True + False + Pmu + + + 1 + 0 + + + + + False + True + 1 + + + + + True + True + True + + + False + True + 2 + + + + + True + True + True + + + False + True + 3 + + + + + + + + + 2 + 1 + diff --git a/iPDC/inc/map_vis.h b/iPDC/inc/map_vis.h index 0ae4ba2..37ac914 100644 --- a/iPDC/inc/map_vis.h +++ b/iPDC/inc/map_vis.h @@ -1,5 +1,7 @@ #include #include +#include "livechart.h" + typedef struct{ OsmGpsMap *util_map; GdkPixbuf *g_red_image; @@ -12,11 +14,13 @@ struct vis_data{ int id; float lat; float lon; - GdkPixbuf *last_image; + GdkColor color; + OsmGpsMapImage *last_image; // TODO: GTimeVal last_update_time; + LiveChartSerie *serie; struct vis_data *next; }; -struct vis_data *head; +struct vis_data *vis_data_head; gboolean update_images(gpointer* pars); \ No newline at end of file diff --git a/iPDC/src/Attack_detect.c b/iPDC/src/Attack_detect.c index 40e5c07..51c6699 100644 --- a/iPDC/src/Attack_detect.c +++ b/iPDC/src/Attack_detect.c @@ -20,11 +20,12 @@ struct vollist int idcode; long double AVERAGE_OF_VOLTAGE; unsigned long long int COUNT; + struct vollist* next; }; struct freqlist *head = NULL; -struct vollist *headvol = NULL +struct vollist *headvol = NULL; gboolean attack_detect_freq(struct data_frame *df) { @@ -111,16 +112,16 @@ gboolean attack_detect_vol(struct data_frame *df) long double v2 = decode_ieee_single(s2); CURR_vol = sqrt((v1 * v1) + (v2 * v2)); } - if (head == NULL) + if (headvol == NULL) { - head = (struct vollist *)malloc(sizeof(struct vollist)); - head->AVERAGE_OF_VOLTAGE = CURR_vol; - head->COUNT = 500; + headvol = (struct vollist *)malloc(sizeof(struct vollist)); + headvol->AVERAGE_OF_VOLTAGE = CURR_vol; + headvol->COUNT = 500; return TRUE; } else { - struct vollist *temp = head; + struct vollist *temp = headvol; struct vollist *previous = NULL; while (temp != NULL) { diff --git a/iPDC/src/Dynamic_time_warping.c b/iPDC/src/Dynamic_time_warping.c index 700b81a..8678814 100644 --- a/iPDC/src/Dynamic_time_warping.c +++ b/iPDC/src/Dynamic_time_warping.c @@ -30,25 +30,25 @@ struct DTWvollist }; -struct DTWfreqlist *head = NULL; -struct DTWvollist *headvol = NULL; +struct DTWfreqlist *dtwhead = NULL; +struct DTWvollist *dtwheadvol = NULL; int DTWfreqDistance(struct data_frame *df) { - if (head == NULL) + if (dtwhead == NULL) { - head = (struct DTWfreqlist *)malloc(sizeof(struct DTWfreqlist)); - head->count_track1 = 0; - head->count_track2 = 0; - head->flag = 0; - head->idcode = to_intconvertor(df->idcode); - head->next = NULL; - head->result=1; + dtwhead = (struct DTWfreqlist *)malloc(sizeof(struct DTWfreqlist)); + dtwhead->count_track1 = 0; + dtwhead->count_track2 = 0; + dtwhead->flag = 0; + dtwhead->idcode = to_intconvertor(df->idcode); + dtwhead->next = NULL; + dtwhead->result=1; return 1; } else { - struct DTWfreqlist *temp = head; + struct DTWfreqlist *temp = dtwhead; struct DTWfreqlist *previous; while (temp != NULL) { @@ -161,20 +161,20 @@ int DTWfreqDistance(struct data_frame *df) int DTWvolDistance(struct data_frame *df) { - if (headvol == NULL) + if (dtwheadvol == NULL) { - headvol = (struct DTWvollist *)malloc(sizeof(struct DTWvollist)); - headvol->count_track1 = 0; - headvol->count_track2 = 0; - headvol->flag = 0; - headvol->idcode = to_intconvertor(df->idcode); - headvol->next = NULL; - headvol->result=1; + dtwheadvol = (struct DTWvollist *)malloc(sizeof(struct DTWvollist)); + dtwheadvol->count_track1 = 0; + dtwheadvol->count_track2 = 0; + dtwheadvol->flag = 0; + dtwheadvol->idcode = to_intconvertor(df->idcode); + dtwheadvol->next = NULL; + dtwheadvol->result=1; return 1; } else { - struct DTWvollist *temp = headvol; + struct DTWvollist *temp = dtwheadvol; struct DTWvollist *previous; while (temp != NULL) { diff --git a/iPDC/src/map_vis.c b/iPDC/src/map_vis.c index 7db20f5..88dff2e 100644 --- a/iPDC/src/map_vis.c +++ b/iPDC/src/map_vis.c @@ -26,6 +26,7 @@ gboolean update_images(gpointer* pars){ pthread_mutex_lock(&mutex_on_TSB); struct data_frame *df = TSB[MAXTSB-1].first_data_frame; struct Lower_Layer_Details *LLptr; + struct vis_data *vis_ptr; if (df == NULL){ pthread_mutex_unlock(&mutex_on_TSB); @@ -45,17 +46,17 @@ gboolean update_images(gpointer* pars){ float lat; float lon; loops++; - // printf("loops: %d\n", loops); + printf("loops: %d\n", loops); id = to_intconvertor(df->idcode); - // printf("id = %d\n",id); + printf("id = %d\n",id); pthread_mutex_lock(&mutex_cfg); temp_cfg = cfgfirst; // Check for the IDCODE in Configuration Frame while(temp_cfg != NULL){ if(id == to_intconvertor(temp_cfg->idcode)){ cfg_match = 1; - // printf("Matched - id : %d\n",id); + printf("Matched - id : %d\n",id); freq_fmt = temp_cfg->pmu[0]->fmt->freq; anal_fmt = temp_cfg->pmu[0]->fmt->analog; phas_fmt = temp_cfg->pmu[0]->fmt->phasor; @@ -70,7 +71,7 @@ gboolean update_images(gpointer* pars){ // get data from df. if(freq_fmt == '1'){ freq = decode_ieee_single(df->dpmu[i]->freq); - // printf("freq = %f\n",freq); + printf("freq = %f\n",freq); }else{ freq = to_intconvertor(df->dpmu[i]->freq)*1e-6+50; } @@ -81,28 +82,42 @@ gboolean update_images(gpointer* pars){ strncpy(last2bytes, df->dpmu[i]->phasors[0]+2, 2); vol_magnitude = to_intconvertor(first2bytes); float imaginary = to_intconvertor(last2bytes); - // printf("vol = %f imag = %f\n",vol_magnitude, imaginary); + printf("vol = %f imag = %f\n",vol_magnitude, imaginary); live_chart_serie_add(serie, freq); // check lower layer details to get longitude and lattitude. - pthread_mutex_lock(&mutex_Lower_Layer_Details); - LLptr = LLfirst; + // pthread_mutex_lock(&mutex_Lower_Layer_Details); + // LLptr = LLfirst; + // match = 0; + // while(LLptr != NULL){ + // printf("pmuid = %d\n",LLptr->pmuid); + // if(LLptr->pmuid == id){ + // match = 1; + // lat = LLptr->latitude; + // lon = LLptr->longitude; + // printf("lat = %f; lon = %f\n",lat,lon); + // break; + // } + // LLptr = LLptr->next; + // } + // pthread_mutex_unlock(&mutex_Lower_Layer_Details); + + vis_ptr = vis_data_head; match = 0; - while(LLptr != NULL){ - // printf("pmuid = %d\n",LLptr->pmuid); - if(LLptr->pmuid == id){ + while(vis_ptr != NULL){ + printf("vis_ptr->id = %d\n",vis_ptr->id); + if(vis_ptr->id == id){ match = 1; - float lat = LLptr->latitude; - float lon = LLptr->longitude; + printf("Matched - id : %d\n",id); break; } - LLptr = LLptr->next; + vis_ptr = vis_ptr->next; } - pthread_mutex_unlock(&mutex_Lower_Layer_Details); - // if(match == 1 && cfg_match == 1){ - // printf("lat = %f, lon = %f, freq = %f\n",lat,lon,freq); + + if(match == 1 && cfg_match == 1){ + printf("lat = %f, lon = %f, freq = %f\n",lat,lon,freq); if(parameters->g_last_image != 0){ osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); } @@ -111,7 +126,7 @@ gboolean update_images(gpointer* pars){ }else{ parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image); } - // } + } df = df->dnext; // i++; k++; diff --git a/iPDC/src/new_pmu_or_pdc.c b/iPDC/src/new_pmu_or_pdc.c index fff224c..a6326d6 100755 --- a/iPDC/src/new_pmu_or_pdc.c +++ b/iPDC/src/new_pmu_or_pdc.c @@ -163,6 +163,7 @@ int add_PMU(char pmuid[], char ip[], char port[], char protocol[], char latitude temp_pmu->request_cfg_frame = 0; temp_pmu->latitude = atof(latitude); temp_pmu->longitude = atof(longitude); + printf(" lat = %f long = %f\n",temp_pmu->latitude,temp_pmu->longitude); temp_pmu->next = NULL; temp_pmu->prev = NULL; diff --git a/iPDC/src/utility_tools.c b/iPDC/src/utility_tools.c index 25a4b21..36db571 100644 --- a/iPDC/src/utility_tools.c +++ b/iPDC/src/utility_tools.c @@ -5,6 +5,7 @@ #include "map_vis.h" #include "utility_tools.h" #include "livechart.h" +#include "connections.h" #define UI_fILE "./assets/utility_tools.ui" #define RED_IMAGE "./assets/red.png" @@ -19,6 +20,106 @@ // } // on closing the window kill the g_timeout_add + +GdkRGBA getIndexColor(int index){ + GdkRGBA color; + // get the color from the index mathematically + switch(index){ + case 0: + color.red = 1.0; + color.green = 0.0; + color.blue = 0.0; + color.alpha = 1.0; + break; + case 1: + color.red = 0.0; + color.green = 1.0; + color.blue = 0.0; + color.alpha = 1.0; + break; + case 2: + color.red = 0.0; + color.green = 0.0; + color.blue = 1.0; + color.alpha = 1.0; + break; + case 3: + color.red = 1.0; + color.green = 1.0; + color.blue = 0.0; + color.alpha = 1.0; + break; + case 4: + color.red = 1.0; + color.green = 0.0; + color.blue = 1.0; + color.alpha = 1.0; + break; + case 5: + color.red = 0.0; + color.green = 1.0; + color.blue = 1.0; + color.alpha = 1.0; + break; + case 6: + color.red = 1.0; + color.green = 0.5; + color.blue = 0.0; + color.alpha = 1.0; + break; + case 7: + color.red = 0.0; + color.green = 0.5; + color.blue = 1.0; + color.alpha = 1.0; + break; + case 8: + color.red = 0.5; + color.green = 1.0; + color.blue = 0.0; + color.alpha = 1.0; + break; + case 9: + color.red = 0.5; + color.green = 0.0; + color.blue = 1.0; + color.alpha = 1.0; + break; + case 10: + color.red = 1.0; + color.green = 0.0; + color.blue = 0.5; + color.alpha = 1.0; + break; + case 11: + color.red = 0.0; + color.green = 1.0; + color.blue = 0.5; + color.alpha = 1.0; + break; + case 12: + color.red = 0.5; + color.green = 0.0; + color.blue = 1.0; + color.alpha = 1.0; + break; + case 13: + color.red = 1.0; + color.green = 0.5; + color.blue = 0.0; + color.alpha = 1.0; + break; + default: + color.red = 0.0+0.1*index; + color.green = 0.0+0.9*index; + color.blue = 0.0+0.5*index; + color.alpha = 1.0; + break; + } + return color; +} + + void on_window_destroy(GtkWidget *widget, gpointer data) { g_source_remove(GPOINTER_TO_UINT(data)); @@ -119,22 +220,43 @@ void utility_tools(GtkButton *but, gpointer udata) dimmension = 0; myParameters parameters = {utdata->util_map, g_red_image, g_green_image, g_last_image}; gpointer data = (gpointer)¶meters; - guint pid = g_timeout_add(20, (GSourceFunc)update_images, data); gtk_widget_set_size_request(GTK_WIDGET(utdata->util_map), 600, 500); gtk_container_add(utdata->map_layout, GTK_WIDGET(utdata->util_map)); // add live chart - serie = live_chart_serie_new("Hello", (LiveChartSerieRenderer*)live_chart_line_new (live_chart_values_new(10000))); + serie = live_chart_serie_new("IIT", (LiveChartSerieRenderer*)live_chart_line_new(live_chart_values_new(10000))); // live_chart set color to the serie - GdkRGBA color; - color.red = 1.0; - color.green = 0.0; - color.blue = 1.0; - color.alpha = 1.0; - + GdkRGBA color = getIndexColor(0); live_chart_path_set_color(live_chart_serie_get_line(serie), &color); + + // iterate over llptr and load the map_vis_head structure + + // vis_data_head = (struct map_vis_head *)malloc(sizeof(struct vis_data)); + + struct Lower_Layer_Details *llptr = LLfirst; + struct vis_data * visptr = vis_data_head; + int index = 0; + while (llptr != NULL) + { + visptr = (struct vis_data *)malloc(sizeof(struct vis_data)); + visptr->id = llptr->pmuid; + visptr->lat = llptr->latitude; + visptr->lon = llptr->longitude; + visptr->last_image = osm_gps_map_image_add(utdata->util_map, llptr->latitude, llptr->longitude, g_red_image); // TODO: change the image + visptr->serie = live_chart_serie_new(llptr->ip, (LiveChartSerieRenderer*)live_chart_line_new(live_chart_values_new(10000))); + // live_chart set color to the serie + GdkRGBA color = getIndexColor(index); + live_chart_path_set_color(live_chart_serie_get_line(visptr->serie), &color); + visptr->next = NULL; + visptr = visptr->next; + index++; + llptr = llptr->next; + } + + guint pid = g_timeout_add(20, (GSourceFunc)update_images, data); + LiveChartConfig *config = live_chart_config_new(); live_chart_yaxis_set_unit(config->y_axis, "mHz"); live_chart_xaxis_set_tick_interval(config->x_axis, 20); @@ -150,6 +272,7 @@ void utility_tools(GtkButton *but, gpointer udata) gtk_widget_set_size_request(GTK_WIDGET(chart), 600, 150); gtk_container_add(utdata->graph_layout, GTK_WIDGET(chart)); +