added interactable buttons

This commit is contained in:
karthikmurakonda 2022-10-19 16:30:42 +05:30
parent 5d8acb43cf
commit bf76be3e97
13 changed files with 403 additions and 140 deletions

Binary file not shown.

View File

@ -1,92 +1,84 @@
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.2 -->
<!-- Generated with glade 3.38.2 -->
<interface>
<requires lib="gtk+" version="3.24"/>
<object class="GtkAdjustment" id="adjustment1">
<property name="upper">100</property>
<property name="step_increment">1</property>
<property name="page_increment">10</property>
</object>
<object class="GtkWindow" id="util_window">
<property name="width_request">800</property>
<property name="height_request">600</property>
<property name="can_focus">False</property>
<child type="titlebar">
<placeholder/>
</child>
<property name="width-request">800</property>
<property name="height-request">600</property>
<property name="can-focus">False</property>
<child>
<object class="GtkLayout" id="util_layout">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="margin_left">10</property>
<property name="margin_right">10</property>
<property name="margin_bottom">3</property>
<property name="can-focus">False</property>
<property name="margin-left">10</property>
<property name="margin-right">10</property>
<property name="margin-bottom">3</property>
<child>
<object class="GtkMenuBar" id="util_menubar">
<property name="width_request">800</property>
<property name="width-request">800</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can_default">True</property>
<property name="resize_mode">immediate</property>
<property name="can-focus">False</property>
<property name="can-default">True</property>
<property name="resize-mode">immediate</property>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_File</property>
<property name="use_underline">True</property>
<property name="use-underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-new</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-open</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-save</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-save-as</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkSeparatorMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-quit</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
</object>
@ -96,47 +88,47 @@
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_Edit</property>
<property name="use_underline">True</property>
<property name="use-underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-cut</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-copy</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-paste</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-delete</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
</object>
@ -146,28 +138,28 @@
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_View</property>
<property name="use_underline">True</property>
<property name="use-underline">True</property>
</object>
</child>
<child>
<object class="GtkMenuItem">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">_Help</property>
<property name="use_underline">True</property>
<property name="use-underline">True</property>
<child type="submenu">
<object class="GtkMenu">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="can-focus">False</property>
<child>
<object class="GtkImageMenuItem">
<property name="label">gtk-about</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="use_underline">True</property>
<property name="use_stock">True</property>
<property name="can-focus">False</property>
<property name="use-underline">True</property>
<property name="use-stock">True</property>
</object>
</child>
</object>
@ -177,88 +169,128 @@
</object>
</child>
<child>
<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid">
<property name="width_request">100</property>
<property name="height_request">80</property>
<property name="width-request">100</property>
<property name="height-request">80</property>
<property name="visible">True</property>
<property name="app_paintable">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="column_spacing">6</property>
<property name="app-paintable">True</property>
<property name="can-focus">False</property>
<property name="margin-top">10</property>
<property name="column-spacing">6</property>
<child>
<!-- n-columns=1 n-rows=5 -->
<object class="GtkGrid">
<property name="width_request">80</property>
<property name="width-request">80</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="row_spacing">35</property>
<property name="can-focus">False</property>
<property name="row-spacing">35</property>
<child>
<object class="GtkButton" id="voltage">
<property name="label" translatable="yes">Voltage</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="current">
<property name="label" translatable="yes">Current</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">1</property>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkButton" id="freq">
<property name="label" translatable="yes">Frequency</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">2</property>
<property name="left-attach">0</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkButton" id="attack_detection">
<property name="label" translatable="yes">Attack Detection</property>
<property name="visible">True</property>
<property name="can_focus">True</property>
<property name="receives_default">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">3</property>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="algorithm">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item id="0" translatable="yes">kmeans</item>
<item id="1" translatable="yes">simple</item>
</items>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
<object class="GtkComboBoxText" id="dimmension">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item id="0" translatable="yes">frequency only</item>
<item id="1" translatable="yes">frequency,voltage</item>
<item id="2" translatable="yes">voltage</item>
</items>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
</packing>
</child>
</object>
<packing>
<property name="left_attach">0</property>
<property name="top_attach">0</property>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLayout" id="map_layout">
<property name="width_request">600</property>
<property name="height_request">500</property>
<property name="width-request">600</property>
<property name="height-request">500</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="border_width">5</property>
<property name="can-focus">False</property>
</object>
<packing>
<property name="left_attach">1</property>
<property name="top_attach">0</property>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="y">30</property>

View File

@ -63,6 +63,8 @@ struct Lower_Layer_Details {
int data_transmission_off;
int pmu_remove;
int request_cfg_frame;
float latitude;
float longitude;
struct Lower_Layer_Details *next;
struct Lower_Layer_Details *prev;

View File

@ -114,6 +114,7 @@ GtkWidget *add_pmu_window, *chkBtn;
GtkWidget *new_window, *setup_display_window;
GtkWidget *p_id, *p_udp, *p_tcp, *p_ip;
GtkWidget *p_port, *p_protocol;
GtkWidget *p_lattitude, *p_longitude;
pthread_t show_sys_time;

View File

@ -5,6 +5,9 @@ typedef struct{
GdkPixbuf *g_red_image;
GdkPixbuf *g_green_image;
OsmGpsMapImage *g_last_image;
int current_selection;
} myParameters;
gboolean update_images(gpointer* pars);

View File

@ -31,7 +31,7 @@
/* Function prototypes */
/* ------------------------------------------------------------------ */
int add_PMU(char pmuid[], char ip[], char port[], char protocol[]);
int add_PMU(char pmuid[], char ip[], char port[], char protocol[], char latitude[], char longitude[]);
void add_PMU_Node(struct Lower_Layer_Details *temp_pmu);

View File

@ -166,4 +166,6 @@ unsigned long int to_long_int_convertor(unsigned char array[]);
uint16_t compute_CRC(unsigned char *message,int length);
float decode_ieee_single(const void *v);
/**************************************** End of File *******************************************************/

View File

@ -8,6 +8,31 @@
#define CH_GET_WIDGET(builder, name, data) \
CH_GET_OBJECT(builder, name, GTK_WIDGET, data)
/* Main data structure definition */
typedef struct _UtData UtData;
struct _UtData
{
/* Main window */
GtkWidget *util_window;
/* ui buttons */
GtkWidget *voltage;
GtkWidget *frequency;
GtkWidget *attack_detection;
GtkWidget *algorithm;
GtkWidget *dimmension;
OsmGpsMap *util_map;
GtkContainer *map_layout;
};
UtData *utdata;
/* UI variables */
int curr_measurement = 0;
int algorithm =0;
int dimmensions = 0;
void utility_tools(GtkButton *but, gpointer udata);

View File

@ -673,13 +673,16 @@ int add_pmu_validation (GtkButton *but, gpointer udata)
/* local variables */
int ret;
char *errmsg1, ip[20], tmp[4];
const char *text, *text1, *text2, *text3;
const char *text, *text1, *text2, *text3, *lattitude, *longitude;
/* Get the text entries filled by user */
text = gtk_entry_get_text(GTK_ENTRY(p_id));
text1 = gtk_entry_get_text(GTK_ENTRY(p_ip));
text2 = gtk_entry_get_text(GTK_ENTRY(p_port));
text3 = gtk_combo_box_text_get_active_text(GTK_COMBO_BOX(p_protocol));
lattitude = gtk_entry_get_text(GTK_ENTRY(p_lattitude));
longitude = gtk_entry_get_text(GTK_ENTRY(p_longitude));
memset(ip,'\0',20);
strcat(ip, text1);
strcpy (tmp, text3);
@ -702,10 +705,22 @@ int add_pmu_validation (GtkButton *but, gpointer udata)
validation_result (errmsg1); /* Show the unsuccess message to user */
return 0;
}
else if(atof(lattitude) > 90 || atof(lattitude) < -90)
{
errmsg1 = " Not a valid Lattitude of Source Device! Try again ";
validation_result (errmsg1); /* Show the unsuccess message to user */
return 0;
}
else if(atof(longitude) > 180 || atof(longitude) < -180)
{
errmsg1 = " Not a valid Longitude of Source Device! Try again ";
validation_result (errmsg1); /* Show the unsuccess message to user */
return 0;
}
else /* Only if all the text_box entries were right */
{
/* call add_PMU() to actual add pmu/pdc and start communication */
ret = add_PMU((char *)text, (char *)text1, (char *)text2, (char *)text3);
ret = add_PMU((char *)text, (char *)text1, (char *)text2, (char *)text3, (char *)lattitude, (char *)longitude);
if (ret == 0)
{
/* Close/destroy the add_pmu_window */
@ -1256,7 +1271,7 @@ void add_pmu (GtkButton *but, gpointer udata)
gtk_window_set_resizable ( GTK_WINDOW (add_pmu_window), FALSE);
/* Create a table of 5 by 2 squares. */
table = gtk_table_new (5, 2, FALSE);
table = gtk_table_new (7, 2, FALSE);
/* Set the spacing to 20 on x and 30 on y */
gtk_table_set_row_spacings (GTK_TABLE (table), 16);
@ -1300,6 +1315,16 @@ void add_pmu (GtkButton *but, gpointer udata)
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 4, 5);
gtk_widget_show (label);
label = gtk_label_new ("x-co-ordinate");
gtk_misc_set_alignment (GTK_MISC(label),0,0);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 5, 6);
gtk_widget_show (label);
label = gtk_label_new ("y-co-ordinate");
gtk_misc_set_alignment (GTK_MISC(label),0,0);
gtk_table_attach_defaults (GTK_TABLE (table), label, 0, 1, 6, 7);
gtk_widget_show (label);
/* Create text boxes for user to enter appropriate values */
p_id = gtk_entry_new();
gtk_entry_set_max_length ((GtkEntry *)p_id, 5);
@ -1316,6 +1341,16 @@ void add_pmu (GtkButton *but, gpointer udata)
gtk_table_attach_defaults (GTK_TABLE (table), p_port, 1, 2, 3, 4);
gtk_widget_show (p_port);
p_lattitude = gtk_entry_new();
gtk_entry_set_max_length ((GtkEntry *)p_lattitude, 10);
gtk_table_attach_defaults (GTK_TABLE (table), p_lattitude, 1, 2, 5, 6);
gtk_widget_show (p_lattitude);
p_longitude = gtk_entry_new();
gtk_entry_set_max_length ((GtkEntry *)p_longitude, 10);
gtk_table_attach_defaults (GTK_TABLE (table), p_longitude, 1, 2, 6, 7);
gtk_widget_show (p_longitude);
/* Create combo boxe for user with some fixed values */
p_protocol = gtk_combo_box_text_new ();
gtk_combo_box_text_append_text(GTK_COMBO_BOX(p_protocol), "UDP");

View File

@ -4,33 +4,70 @@
#include "parser.h"
#include "osm-gps-map.h"
#include "Attack_detect.h"
#include "connections.h"
// #include "utility_tools.h"
gboolean update_images(gpointer* pars){
int match=0,id;
myParameters* parameters = (myParameters*) pars;
struct data_frame *df = TSB[0].first_data_frame;
struct Lower_Layer_Details *LLptr;
if (df == NULL){
return TRUE;
}
int freq = to_intconvertor(df->dpmu[0]->freq);
gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
// if (curr_measurement==1)
// {
while (df != NULL){
id = to_intconvertor(df->idcode);
printf("id = %d\n",id);
LLptr = LLfirst;
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);
// 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 > 300){
// if (green){
// parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image);
// }else{
// parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_red_image);
// }
if(parameters->g_last_image != 0){
osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
}
if (green){
parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image);
}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;
}

View File

@ -82,7 +82,7 @@
/* created for each added lower layer PMU/PDC accoring to the protcol (TCP/UDP).*/
/* ---------------------------------------------------------------------------- */
int add_PMU(char pmuid[], char ip[], char port[], char protocol[]) {
int add_PMU(char pmuid[], char ip[], char port[], char protocol[], char latitude[], char longitude[]) {
int err;
int flag = 0;
@ -161,6 +161,8 @@ int add_PMU(char pmuid[], char ip[], char port[], char protocol[]) {
temp_pmu->data_transmission_off = 0;
temp_pmu->pmu_remove = 0;
temp_pmu->request_cfg_frame = 0;
temp_pmu->latitude = atof(latitude);
temp_pmu->longitude = atof(longitude);
temp_pmu->next = NULL;
temp_pmu->prev = NULL;

View File

@ -55,6 +55,9 @@
#include <pthread.h>
#include <stdint.h>
#include <time.h>
#include <float.h>
#include <assert.h>
#include <math.h>
#include "parser.h"
#include "global.h"
#include "dallocate.h"
@ -62,6 +65,58 @@
#include "connections.h"
#include "recreate.h"
float decode_ieee_single(const void *v) {
const unsigned char *data = v;
int s, e;
unsigned long src;
long f;
float value;
src = ((unsigned long)data[0] << 24) |
((unsigned long)data[1] << 16) |
((unsigned long)data[2] << 8) |
((unsigned long)data[3]);
s = (src & 0x80000000UL) >> 31;
e = (src & 0x7F800000UL) >> 23;
f = (src & 0x007FFFFFUL);
if (e == 255 && f != 0) {
/* NaN (Not a Number) */
value = DBL_MAX;
} else if (e == 255 && f == 0 && s == 1) {
/* Negative infinity */
value = -DBL_MAX;
} else if (e == 255 && f == 0 && s == 0) {
/* Positive infinity */
value = DBL_MAX;
} else if (e > 0 && e < 255) {
/* Normal number */
f += 0x00800000UL;
if (s) f = -f;
value = ldexp(f, e - 150);
} else if (e == 0 && f != 0) {
/* Denormal number */
if (s) f = -f;
value = ldexp(f, -149);
} else if (e == 0 && f == 0 && s == 1) {
/* Negative zero */
value = 0;
} else if (e == 0 && f == 0 && s == 0) {
/* Positive zero */
value = 0;
} else {
/* Never happens */
printf("s = %d, e = %d, f = %lu\n", s, e, f);
assert(!"Woops, unhandled case in decode_ieee_single()");
}
return value;
}
/* ---------------------------------------------------------------------------- */
/* FUNCTION cfgparser(): */
/* It creates configuration objects for the received configuration frames. */

View File

@ -3,6 +3,7 @@
#include "parser.h"
#include "osm-gps-map.h"
#include "map_vis.h"
#include "utility_tools.h"
#define UI_fILE "./assets/utility_tools.ui"
#define RED_IMAGE "./assets/red.png"
@ -24,10 +25,47 @@ void on_window_destroy(GtkWidget *widget, gpointer data)
gtk_main_quit();
}
// on clicking the button frequency
void on_frequency_clicked(GtkButton *but, gpointer udata)
{
curr_measurement = 1;
gtk_widget_hide(utdata->algorithm);
gtk_widget_hide(utdata->dimmension);
gtk_widget_set_sensitive(utdata->voltage, TRUE);
gtk_widget_set_sensitive(utdata->frequency, FALSE);
gtk_widget_set_sensitive(utdata->attack_detection, TRUE);
// printf("Frequency\n");
}
// on clicking the button attack_detection
void on_attack_detection_clicked(GtkButton *but, gpointer udata)
{
curr_measurement = 2;
gtk_widget_set_sensitive(utdata->voltage, TRUE);
gtk_widget_set_sensitive(utdata->frequency, TRUE);
gtk_widget_set_sensitive(utdata->attack_detection, FALSE);
gtk_widget_show(utdata->algorithm);
gtk_widget_show(utdata->dimmension);
// printf("Attack Detection\n");
}
// on clicking the button voltage
void on_voltage_clicked(GtkButton *but, gpointer udata)
{
curr_measurement = 0;
gtk_widget_hide(utdata->algorithm);
gtk_widget_hide(utdata->dimmension);
gtk_widget_set_sensitive(utdata->voltage, FALSE);
gtk_widget_set_sensitive(utdata->frequency, TRUE);
gtk_widget_set_sensitive(utdata->attack_detection, TRUE);
// printf("Voltage\n");
}
void utility_tools(GtkButton *but, gpointer udata)
{
OsmGpsMap *util_map;
GtkWidget *window;
GdkPixbuf *g_red_image;
GdkPixbuf *g_green_image;
OsmGpsMapImage *g_last_image;
@ -35,35 +73,66 @@ void utility_tools(GtkButton *but, gpointer udata)
GtkBuilder *builder;
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);
}
utdata = g_slice_new(UtData);
utdata->util_window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window"));
utdata->voltage = GTK_WIDGET(gtk_builder_get_object(builder, "voltage"));
utdata->frequency = GTK_WIDGET(gtk_builder_get_object(builder, "freq"));
utdata->attack_detection = GTK_WIDGET(gtk_builder_get_object(builder, "attack_detection"));
utdata->algorithm = GTK_WIDGET(gtk_builder_get_object(builder, "algorithm"));
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"));
gtk_widget_set_sensitive(utdata->voltage, FALSE);
gtk_widget_set_visible(utdata->algorithm, FALSE);
gtk_widget_set_visible(utdata->dimmension, FALSE);
g_signal_connect(utdata->attack_detection, "clicked", G_CALLBACK(on_attack_detection_clicked), NULL);
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);
window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window"));
GtkContainer *map_container = GTK_CONTAINER(gtk_builder_get_object(builder, "map_layout"));
util_map = g_object_new (OSM_TYPE_GPS_MAP,
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 (util_map, 15.4589, 75.0078, 10);
osm_gps_map_set_center_and_zoom (utdata->util_map, 15.4589, 75.0078, 10);
g_last_image = osm_gps_map_image_add(util_map,15.4589, 75.0078, g_red_image);
g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
myParameters parameters = {util_map, g_red_image, g_green_image, g_last_image};
// 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);
myParameters parameters = {utdata->util_map, g_red_image, g_green_image, g_last_image};
gpointer data = (gpointer) &parameters;
guint pid = g_timeout_add(20, (GSourceFunc) update_images, data);
gtk_widget_set_size_request(GTK_WIDGET(util_map), 600, 500);
gtk_widget_set_size_request(GTK_WIDGET(utdata->util_map), 600, 500);
gtk_container_add(map_container, GTK_WIDGET(util_map));
g_signal_connect(window, "destroy", G_CALLBACK(on_window_destroy), GUINT_TO_POINTER(pid));
gtk_container_add(utdata->map_layout, GTK_WIDGET(utdata->util_map));
g_signal_connect(utdata->util_window, "destroy", G_CALLBACK(on_window_destroy), GUINT_TO_POINTER(pid));
gtk_widget_show_all(utdata->util_window);
gtk_widget_hide(utdata->algorithm);
gtk_widget_hide(utdata->dimmension);
gtk_widget_show_all(window);
gtk_main();
}