From 5886069a3db97cf36b4f6fc3d01f13d031386d89 Mon Sep 17 00:00:00 2001 From: karthikmurakonda Date: Thu, 20 Oct 2022 14:26:58 +0530 Subject: [PATCH] Basic model of line chart --- iPDC/Makefile | 4 +- iPDC/assets/utility_tools.ui | 29 ++-- iPDC/assets/utility_tools.ui~ | 302 ++++++++++++++++++++++++++++++++++ iPDC/inc/map_vis.h | 1 - iPDC/inc/utility_tools.h | 8 +- iPDC/src/map_vis.c | 75 +++++---- iPDC/src/utility_tools.c | 86 ++++++---- 7 files changed, 413 insertions(+), 92 deletions(-) create mode 100644 iPDC/assets/utility_tools.ui~ diff --git a/iPDC/Makefile b/iPDC/Makefile index 28810af..0f7a395 100755 --- a/iPDC/Makefile +++ b/iPDC/Makefile @@ -46,7 +46,7 @@ FILE6 = iPDC.desktop CC = gcc LIBS = -lpthread -LDLIBS=`pkg-config --cflags --libs gtk+-3.0 osmgpsmap-1.0 gee-0.8` +LDLIBS=`pkg-config --cflags --libs gtk+-3.0 osmgpsmap-1.0 gee-0.8` lib/liblivechart.so lib/liblivechart_static.a -Wl,--rpath=./lib CFLAGS=-g -I./inc -I./lib -fcommon `pkg-config --cflags --libs gtk+-3.0 osmgpsmap-1.0 gee-0.8` PROGRAM = iPDC @@ -57,7 +57,7 @@ CLEAN_OBJECTS = $(wildcard bin/*.o) $(PROGRAM) all: $(PROGRAM) $(PROGRAM): $(OBJECT_FILES) - $(CC) $(CFLAGS) $(OBJECT_FILES) -o $(PROGRAM) $(LDLIBS) + $(CC) $(CFLAGS) $(OBJECT_FILES) -o $(PROGRAM) $(LDLIBS) bin/%.o: src/%.c $(CC) $(CFLAGS) -c $< -o $@ diff --git a/iPDC/assets/utility_tools.ui b/iPDC/assets/utility_tools.ui index 3dba50e..ce69fd8 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 @@ -271,22 +271,15 @@ - - - - - - - - - - - - - - - - + + 150 + True + False + + + 1 + 1 + diff --git a/iPDC/assets/utility_tools.ui~ b/iPDC/assets/utility_tools.ui~ new file mode 100644 index 0000000..3dba50e --- /dev/null +++ b/iPDC/assets/utility_tools.ui~ @@ -0,0 +1,302 @@ + + + + + + 800 + 600 + False + + + True + False + 10 + 10 + 3 + + + 800 + True + False + True + immediate + + + True + False + _File + True + + + True + False + + + gtk-new + True + False + True + True + + + + + gtk-open + True + False + True + True + + + + + gtk-save + True + False + True + True + + + + + gtk-save-as + True + False + True + True + + + + + True + False + + + + + gtk-quit + True + False + True + True + + + + + + + + + True + False + _Edit + True + + + True + False + + + gtk-cut + True + False + True + True + + + + + gtk-copy + True + False + True + True + + + + + gtk-paste + True + False + True + True + + + + + gtk-delete + True + False + True + True + + + + + + + + + True + False + _View + True + + + + + True + False + _Help + True + + + True + False + + + gtk-about + True + False + True + True + + + + + + + + + + + + 100 + 80 + True + True + False + 10 + 6 + + + + 80 + True + False + 35 + + + Voltage + True + True + True + + + 0 + 0 + + + + + Frequency + True + True + True + + + 0 + 1 + + + + + Attack Detection + True + True + True + + + 0 + 2 + + + + + True + False + 0 + + kmeans + simple + + + + 0 + 3 + + + + + True + False + 0 + + frequency only + frequency,voltage + voltage + + + + 0 + 4 + + + + + 0 + 0 + + + + + 600 + 500 + True + False + + + 1 + 0 + + + + + + + + + + + + + + + + + + + + + + + + + + 30 + + + + + + diff --git a/iPDC/inc/map_vis.h b/iPDC/inc/map_vis.h index 90baf2b..ec05f5e 100644 --- a/iPDC/inc/map_vis.h +++ b/iPDC/inc/map_vis.h @@ -9,5 +9,4 @@ typedef struct{ } myParameters; - gboolean update_images(gpointer* pars); \ No newline at end of file diff --git a/iPDC/inc/utility_tools.h b/iPDC/inc/utility_tools.h index 5e49756..ba4e105 100644 --- a/iPDC/inc/utility_tools.h +++ b/iPDC/inc/utility_tools.h @@ -1,6 +1,7 @@ #include #include #include "osm-gps-map.h" +#include "livechart.h" /* Convenience macros for obtaining objects from UI file */ #define CH_GET_OBJECT(builder, name, type, data) \ @@ -24,14 +25,11 @@ struct _UtData GtkWidget *dimmension; OsmGpsMap *util_map; GtkContainer *map_layout; + GtkContainer *graph_layout; }; UtData *utdata; - -/* UI variables */ -int curr_measurement = 0; -int algorithm =0; -int dimmensions = 0; +LiveChartSerie *serie; diff --git a/iPDC/src/map_vis.c b/iPDC/src/map_vis.c index d9277b2..7e22a8b 100644 --- a/iPDC/src/map_vis.c +++ b/iPDC/src/map_vis.c @@ -6,13 +6,19 @@ #include "Attack_detect.h" #include "connections.h" #include "livechart.h" -// #include "utility_tools.h" +#include "utility_tools.h" +extern int curr_measurement; +extern int algorithm; +extern int dimmensions; + +// debug +int loops = 0; gboolean update_images(gpointer* pars){ int match=0,id; myParameters* parameters = (myParameters*) pars; - struct data_frame *df = TSB[0].first_data_frame; + struct data_frame *df = TSB[4].first_data_frame; struct Lower_Layer_Details *LLptr; if (df == NULL){ @@ -20,36 +26,38 @@ gboolean update_images(gpointer* pars){ } // if (curr_measurement==1) // { - while (df != NULL){ - id = to_intconvertor(df->idcode); - printf("id = %d\n",id); + int freq = to_intconvertor(df->dpmu[0]->freq)-200; + live_chart_serie_add(serie, freq); + loops++; + printf("loops: %d\n", loops); + // id = to_intconvertor(df->idcode); + // printf("id = %d\n",id); - LLptr = LLfirst; + // LLptr = LLfirst; - while(LLptr != NULL){ - printf("pmuid = %d\n",LLptr->pmuid); - if(LLptr->pmuid == id){ - match = 1; - break; - } - LLptr = LLptr->next; - } + // while(LLptr != NULL){ + // printf("pmuid = %d\n",LLptr->pmuid); + // if(LLptr->pmuid == id){ + // match = 1; + // break; + // } + // LLptr = LLptr->next; + // } - if(match == 1){ - float lat = LLptr->latitude; - float lon = LLptr->longitude; - float freq = to_intconvertor(df->dpmu[0]->freq)*0.001+50; - printf("lat = %f, lon = %f, freq = %f\n",lat,lon,freq); + // if(match == 1){ + float lat = 79.347312; + float lon = -69.439209; + // float freq = to_intconvertor(df->dpmu[0]->freq)*0.001+50; + printf("lat = %f, lon = %f, freq = %d\n",lat,lon,freq); // gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY); - - if(parameters->g_last_image != 0){ - osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); - } - if (freq > 50.300){ - parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_green_image); - }else{ - parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image); - } + // if(parameters->g_last_image != 0){ + // osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); + // } + // if (freq > 50.300){ + // parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_green_image); + // }else{ + // parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image); + // } // if(parameters->g_last_image != 0){ // osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image); // } @@ -58,15 +66,10 @@ gboolean update_images(gpointer* pars){ // }else{ // parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_red_image); // } - - - } - df = df->dnext; - } +// } // } - - gtk_widget_queue_draw(GTK_WIDGET(parameters->util_map)); return TRUE; -} \ No newline at end of file +} + diff --git a/iPDC/src/utility_tools.c b/iPDC/src/utility_tools.c index fce1144..f81cf78 100644 --- a/iPDC/src/utility_tools.c +++ b/iPDC/src/utility_tools.c @@ -1,15 +1,18 @@ -#include +#include #include "align_sort.h" #include "parser.h" #include "osm-gps-map.h" #include "map_vis.h" #include "utility_tools.h" +#include "livechart.h" #define UI_fILE "./assets/utility_tools.ui" #define RED_IMAGE "./assets/red.png" #define GREEN_IMAGE "./assets/green.png" - +int curr_measurement = 0; +int algorithm =0; +int dimmensions = 0; // void change_image(OsmGpsMap *map, float lat, float lon, OsmGpsMapImage *image) // { @@ -35,7 +38,6 @@ void on_frequency_clicked(GtkButton *but, gpointer udata) gtk_widget_set_sensitive(utdata->frequency, FALSE); gtk_widget_set_sensitive(utdata->attack_detection, TRUE); - // printf("Frequency\n"); } @@ -71,16 +73,14 @@ void utility_tools(GtkButton *but, gpointer udata) OsmGpsMapImage *g_last_image; // ------------------- GtkBuilder *builder; - GError *error = NULL; + GError *error = NULL; builder = gtk_builder_new(); - - - if(!gtk_builder_add_from_file(builder, UI_fILE, &error)) - { - g_warning("%s", error->message); - g_free(error); - } + if (!gtk_builder_add_from_file(builder, UI_fILE, &error)) + { + g_warning("%s", error->message); + g_free(error); + } utdata = g_slice_new(UtData); utdata->util_window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window")); @@ -91,7 +91,8 @@ void utility_tools(GtkButton *but, gpointer udata) utdata->dimmension = GTK_WIDGET(gtk_builder_get_object(builder, "dimmension")); // utdata->util_map = GTK_WIDGET(gtk_builder_get_object(builder, "util_map")); utdata->map_layout = GTK_CONTAINER(gtk_builder_get_object(builder, "map_layout")); - + utdata->graph_layout = GTK_CONTAINER(gtk_builder_get_object(builder, "graph_layout")); + gtk_widget_set_sensitive(utdata->voltage, FALSE); gtk_widget_set_visible(utdata->algorithm, FALSE); gtk_widget_set_visible(utdata->dimmension, FALSE); @@ -100,35 +101,60 @@ void utility_tools(GtkButton *but, gpointer udata) g_signal_connect(utdata->frequency, "clicked", G_CALLBACK(on_frequency_clicked), NULL); g_signal_connect(utdata->voltage, "clicked", G_CALLBACK(on_voltage_clicked), NULL); + g_red_image = gdk_pixbuf_new_from_file_at_size(RED_IMAGE, 24, 24, NULL); + g_green_image = gdk_pixbuf_new_from_file_at_size(GREEN_IMAGE, 24, 24, NULL); - - - g_red_image = gdk_pixbuf_new_from_file_at_size (RED_IMAGE, 24,24,NULL); - g_green_image = gdk_pixbuf_new_from_file_at_size (GREEN_IMAGE, 24,24,NULL); - - - - utdata->util_map = g_object_new (OSM_TYPE_GPS_MAP, - "map-source", OSM_GPS_MAP_SOURCE_OPENSTREETMAP, - "tile-cache", "/tmp/", - NULL); - osm_gps_map_set_center_and_zoom (utdata->util_map, 15.4589, 75.0078, 10); + utdata->util_map = g_object_new(OSM_TYPE_GPS_MAP, + "map-source", OSM_GPS_MAP_SOURCE_OSMC_TRAILS, + "tile-cache", "/tmp/", + NULL); + osm_gps_map_set_center_and_zoom(utdata->util_map, 15.4589, 75.0078, 10); // TODO: add the points to window. - g_last_image = osm_gps_map_image_add(utdata->util_map,15.4589, 75.0078, g_red_image); - g_last_image = osm_gps_map_image_add(utdata->util_map,15.518597, 74.925584, g_green_image); - - + g_last_image = osm_gps_map_image_add(utdata->util_map, 15.4589, 75.0078, g_red_image); + g_last_image = osm_gps_map_image_add(utdata->util_map, 15.518597, 74.925584, g_green_image); 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); + 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))); + // 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; + + live_chart_path_set_color(live_chart_serie_get_line(serie), &color); + 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); + live_chart_xaxis_set_tick_length(config->x_axis, 100); + live_chart_yaxis_update_bounds(config->y_axis, 1); + live_chart_path_set_visible(config->x_axis->lines, FALSE); + + LiveChartChart *chart = live_chart_chart_new(config); + live_chart_chart_add_serie(chart, serie); + + // gtk_widget_set_hexpand(GTK_WIDGET(chart), TRUE); + // gtk_widget_set_vexpand(GTK_WIDGET(chart), TRUE); + gtk_widget_set_size_request(GTK_WIDGET(chart), 600, 150); + + gtk_container_add(utdata->graph_layout, GTK_WIDGET(chart)); + + + + g_signal_connect(utdata->util_window, "destroy", G_CALLBACK(on_window_destroy), GUINT_TO_POINTER(pid)); + // gtk_widget_set_vexpand(GTK_WIDGET(utdata->util_map), TRUE); + // gtk_widget_set_hexpand(GTK_WIDGET(utdata->util_map), TRUE); gtk_widget_show_all(utdata->util_window); gtk_widget_hide(utdata->algorithm);