graph drawing(unrefractored)

This commit is contained in:
karthikmurakonda 2022-10-25 21:43:07 +05:30
parent 5886069a3d
commit e88e009376
3 changed files with 57 additions and 47 deletions

View File

@ -31,6 +31,11 @@ struct _UtData
UtData *utdata; UtData *utdata;
LiveChartSerie *serie; LiveChartSerie *serie;
// global variables
int curr_measurement;
int algorithm;
int dimmension;
void utility_tools(GtkButton *but, gpointer udata); void utility_tools(GtkButton *but, gpointer udata);

View File

@ -8,9 +8,6 @@
#include "livechart.h" #include "livechart.h"
#include "utility_tools.h" #include "utility_tools.h"
extern int curr_measurement;
extern int algorithm;
extern int dimmensions;
// debug // debug
int loops = 0; int loops = 0;
@ -18,56 +15,64 @@ int loops = 0;
gboolean update_images(gpointer* pars){ gboolean update_images(gpointer* pars){
int match=0,id; int match=0,id;
myParameters* parameters = (myParameters*) pars; myParameters* parameters = (myParameters*) pars;
struct data_frame *df = TSB[4].first_data_frame; struct data_frame *df = TSB[0].first_data_frame;
struct Lower_Layer_Details *LLptr; struct Lower_Layer_Details *LLptr;
if (df == NULL){ if (df == NULL){
return TRUE; return TRUE;
} }
// if (curr_measurement==1) if (curr_measurement==0)
// { {
int freq = to_intconvertor(df->dpmu[0]->freq)-200; int n = df->num_pmu;
if (n==0) return TRUE;
int i = 0;
int freq;
while (i < n){
freq = to_intconvertor(df->dpmu[i]->freq)-200;
live_chart_serie_add(serie, freq); live_chart_serie_add(serie, freq);
loops++; loops++;
printf("loops: %d\n", loops); printf("loops: %d\n", loops);
// id = to_intconvertor(df->idcode); id = to_intconvertor(TSB[0].idlist[i].idcode);
// printf("id = %d\n",id); printf("id = %d\n",id);
// LLptr = LLfirst; LLptr = LLfirst;
match = 0;
while(LLptr != NULL){
printf("pmuid = %d\n",LLptr->pmuid);
if(LLptr->pmuid == id){
match = 1;
break;
}
LLptr = LLptr->next;
}
// while(LLptr != NULL){ if(match == 1){
// printf("pmuid = %d\n",LLptr->pmuid);
// if(LLptr->pmuid == id){
// match = 1;
// break;
// }
// LLptr = LLptr->next;
// }
// if(match == 1){
float lat = 79.347312; float lat = 79.347312;
float lon = -69.439209; float lon = -69.439209;
// float freq = to_intconvertor(df->dpmu[0]->freq)*0.001+50; float freq = to_intconvertor(df->dpmu[i]->freq)*0.001+50;
printf("lat = %f, lon = %f, freq = %d\n",lat,lon,freq); printf("lat = %f, lon = %f, freq = %f\n",lat,lon,freq);
// gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY); gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
// if(parameters->g_last_image != 0){ 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); // osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
// } }
// if (freq > 50.300){ if (green){
// parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_green_image); parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,15.518597, 74.925584, parameters->g_green_image);
// }else{ }else{
// parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image); 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); df = df->dnext;
// } i++;
// 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);
// }
// }
// }
gtk_widget_queue_draw(GTK_WIDGET(parameters->util_map)); gtk_widget_queue_draw(GTK_WIDGET(parameters->util_map));
return TRUE; return TRUE;

View File

@ -10,9 +10,6 @@
#define RED_IMAGE "./assets/red.png" #define RED_IMAGE "./assets/red.png"
#define GREEN_IMAGE "./assets/green.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) // void change_image(OsmGpsMap *map, float lat, float lon, OsmGpsMapImage *image)
// { // {
@ -38,7 +35,7 @@ void on_frequency_clicked(GtkButton *but, gpointer udata)
gtk_widget_set_sensitive(utdata->frequency, FALSE); gtk_widget_set_sensitive(utdata->frequency, FALSE);
gtk_widget_set_sensitive(utdata->attack_detection, TRUE); gtk_widget_set_sensitive(utdata->attack_detection, TRUE);
// printf("Frequency\n"); printf("Frequency\n");
} }
// on clicking the button attack_detection // on clicking the button attack_detection
@ -51,7 +48,7 @@ void on_attack_detection_clicked(GtkButton *but, gpointer udata)
gtk_widget_show(utdata->algorithm); gtk_widget_show(utdata->algorithm);
gtk_widget_show(utdata->dimmension); gtk_widget_show(utdata->dimmension);
// printf("Attack Detection\n"); printf("Attack Detection\n");
} }
// on clicking the button voltage // on clicking the button voltage
@ -63,7 +60,7 @@ void on_voltage_clicked(GtkButton *but, gpointer udata)
gtk_widget_set_sensitive(utdata->voltage, FALSE); gtk_widget_set_sensitive(utdata->voltage, FALSE);
gtk_widget_set_sensitive(utdata->frequency, TRUE); gtk_widget_set_sensitive(utdata->frequency, TRUE);
gtk_widget_set_sensitive(utdata->attack_detection, TRUE); gtk_widget_set_sensitive(utdata->attack_detection, TRUE);
// printf("Voltage\n"); printf("Voltage\n");
} }
void utility_tools(GtkButton *but, gpointer udata) void utility_tools(GtkButton *but, gpointer udata)
@ -114,6 +111,9 @@ void utility_tools(GtkButton *but, gpointer udata)
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.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.518597, 74.925584, g_green_image);
curr_measurement = 0;
algorithm = 0;
dimmension = 0;
myParameters parameters = {utdata->util_map, g_red_image, g_green_image, g_last_image}; myParameters parameters = {utdata->util_map, g_red_image, g_green_image, g_last_image};
gpointer data = (gpointer)&parameters; gpointer data = (gpointer)&parameters;
guint pid = g_timeout_add(20, (GSourceFunc)update_images, data); guint pid = g_timeout_add(20, (GSourceFunc)update_images, data);