basic color changing working
This commit is contained in:
parent
eda4d763e5
commit
59bed77548
|
@ -2,9 +2,10 @@
|
||||||
#include<time.h>
|
#include<time.h>
|
||||||
#include<stdio.h>
|
#include<stdio.h>
|
||||||
#include<stdlib.h>
|
#include<stdlib.h>
|
||||||
|
#include<gtk/gtk.h>
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY)
|
gboolean attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY)
|
||||||
{
|
{
|
||||||
// printf("freq: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->freq)));
|
// printf("freq: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->freq)));
|
||||||
// printf("analog: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->analog)));
|
// printf("analog: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->analog)));
|
||||||
|
@ -16,18 +17,20 @@ void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_O
|
||||||
*SUM_OF_FREQUENCY+=CURR_FREQ;
|
*SUM_OF_FREQUENCY+=CURR_FREQ;
|
||||||
float FREQ_AVG=*SUM_OF_FREQUENCY/(*COUNT*1.0f);
|
float FREQ_AVG=*SUM_OF_FREQUENCY/(*COUNT*1.0f);
|
||||||
float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100;
|
float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100;
|
||||||
|
gboolean detect;
|
||||||
/* detecting based on thershold */
|
/* detecting based on thershold */
|
||||||
float THRESHOLD=70;
|
float THRESHOLD=60;
|
||||||
if(DETECT_PERCENT>THRESHOLD)
|
if(DETECT_PERCENT>THRESHOLD)
|
||||||
{
|
{
|
||||||
|
detect=FALSE;
|
||||||
printf("\033[0;31m");
|
printf("\033[0;31m");
|
||||||
printf("ATTACK DETECTED!");
|
printf("ATTACK DETECTED!");
|
||||||
printf("\033[0m");
|
printf("\033[0m");
|
||||||
printf(" Detect_percent: %f\n",DETECT_PERCENT);
|
// intf(" Detect_percent: %f\n",DETECT_PERCENT);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
detect=TRUE;
|
||||||
printf("\033[0;32m");
|
printf("\033[0;32m");
|
||||||
printf("NO PROBLEM :)\n");
|
printf("NO PROBLEM :)\n");
|
||||||
printf("\033[0m");
|
printf("\033[0m");
|
||||||
|
@ -51,6 +54,7 @@ void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_O
|
||||||
*SUM_OF_FREQUENCY=CURR_FREQ;
|
*SUM_OF_FREQUENCY=CURR_FREQ;
|
||||||
*COUNT=1;
|
*COUNT=1;
|
||||||
}
|
}
|
||||||
|
return detect;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pavan changes */
|
/* pavan changes */
|
|
@ -1,10 +1,11 @@
|
||||||
/* pavan changes */
|
/* pavan changes */
|
||||||
|
#include <time.h>
|
||||||
|
#include <gtk/gtk.h>
|
||||||
/* variables declared of attack_detect function */
|
/* variables declared of attack_detect function */
|
||||||
float SUM_OF_FREQUENCY=0;
|
float SUM_OF_FREQUENCY=0;
|
||||||
float COUNT=0;
|
float COUNT=0;
|
||||||
time_t START;
|
time_t START;
|
||||||
|
|
||||||
/* function declared */
|
/* function declared */
|
||||||
void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY);
|
gboolean attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY);
|
||||||
/* pavan changes */
|
/* pavan changes */
|
|
@ -0,0 +1,51 @@
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include "align_sort.h"
|
||||||
|
#include "map_vis.h"
|
||||||
|
#include "parser.h"
|
||||||
|
#include "osm-gps-map.h"
|
||||||
|
#include "Attack_detect.h"
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
OsmGpsMap *util_map;
|
||||||
|
GdkPixbuf *g_red_image;
|
||||||
|
GdkPixbuf *g_green_image;
|
||||||
|
OsmGpsMapImage *g_last_image;
|
||||||
|
} myParameters;
|
||||||
|
|
||||||
|
gboolean update_images(gpointer* pars){
|
||||||
|
myParameters* parameters = (myParameters*) pars;
|
||||||
|
struct data_frame *df = TSB[0].first_data_frame;
|
||||||
|
if(parameters->g_green_image == NULL){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (parameters->util_map == NULL){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (df == NULL){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
int freq = to_intconvertor(df->dpmu[0]->freq);
|
||||||
|
gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
||||||
|
if(parameters->util_map != NULL){
|
||||||
|
|
||||||
|
// if(parameters->g_last_image != 0){
|
||||||
|
// osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
|
||||||
|
// }
|
||||||
|
// if (freq > 300){
|
||||||
|
// 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_green_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_green_image);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_queue_draw(GTK_WIDGET(parameters->util_map));
|
||||||
|
return TRUE;
|
||||||
|
}
|
|
@ -61,8 +61,6 @@
|
||||||
#include "align_sort.h"
|
#include "align_sort.h"
|
||||||
#include "connections.h"
|
#include "connections.h"
|
||||||
#include "recreate.h"
|
#include "recreate.h"
|
||||||
#include "utility_tools.h"
|
|
||||||
#include "Attack_detect.h"
|
|
||||||
|
|
||||||
/* ---------------------------------------------------------------------------- */
|
/* ---------------------------------------------------------------------------- */
|
||||||
/* FUNCTION cfgparser(): */
|
/* FUNCTION cfgparser(): */
|
||||||
|
@ -1274,26 +1272,26 @@ int dataparser(unsigned char data[]) {
|
||||||
}
|
}
|
||||||
|
|
||||||
/*pavan changes*/
|
/*pavan changes*/
|
||||||
attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
// attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
||||||
/*pavan changes*/
|
/*pavan changes*/
|
||||||
|
|
||||||
// temp code
|
// temp code
|
||||||
/* karthik changes*/
|
/* karthik changes*/
|
||||||
int freq = to_intconvertor(df->dpmu[0]->freq);
|
// int freq = to_intconvertor(df->dpmu[0]->freq);
|
||||||
if(util_map != NULL){
|
// if(util_map != NULL){
|
||||||
g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL);
|
// g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL);
|
||||||
g_green_image = gdk_pixbuf_new_from_file_at_size ("green.png", 24,24,NULL);
|
// g_green_image = gdk_pixbuf_new_from_file_at_size ("green.png", 24,24,NULL);
|
||||||
if(g_last_image != 0){
|
// if(g_last_image != 0){
|
||||||
osm_gps_map_image_remove(util_map, g_last_image);
|
// osm_gps_map_image_remove(util_map, g_last_image);
|
||||||
}
|
// }
|
||||||
if (freq > 300){
|
// if (freq > 300){
|
||||||
g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
|
// g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
|
||||||
}else{
|
// }else{
|
||||||
g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
|
// g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image);
|
||||||
}
|
// }
|
||||||
gtk_widget_show_all(GTK_WIDGET(util_map));
|
// gtk_widget_show_all(GTK_WIDGET(util_map));
|
||||||
|
|
||||||
}
|
// }
|
||||||
/* karthik changes */
|
/* karthik changes */
|
||||||
|
|
||||||
if((config_change == 14) ||(config_change == 10))
|
if((config_change == 14) ||(config_change == 10))
|
||||||
|
|
|
@ -1,5 +1,8 @@
|
||||||
#include<gtk/gtk.h>
|
#include<gtk/gtk.h>
|
||||||
#include "utility_tools.h"
|
#include "utility_tools.h"
|
||||||
|
#include "align_sort.h"
|
||||||
|
#include "parser.h"
|
||||||
|
#include "Attack_detect.h"
|
||||||
|
|
||||||
#define UI_fILE "./utility_tools.ui"
|
#define UI_fILE "./utility_tools.ui"
|
||||||
|
|
||||||
|
@ -12,9 +15,59 @@
|
||||||
// osm_gps_map_image_add(map, lat, lon, image);
|
// osm_gps_map_image_add(map, lat, lon, image);
|
||||||
// }
|
// }
|
||||||
|
|
||||||
|
typedef struct{
|
||||||
|
OsmGpsMap *util_map;
|
||||||
|
GdkPixbuf *g_red_image;
|
||||||
|
GdkPixbuf *g_green_image;
|
||||||
|
OsmGpsMapImage *g_last_image;
|
||||||
|
} myParameters;
|
||||||
|
|
||||||
|
gboolean update_images(gpointer* pars){
|
||||||
|
myParameters* parameters = (myParameters*) pars;
|
||||||
|
struct data_frame *df = TSB[0].first_data_frame;
|
||||||
|
if(parameters->g_green_image == NULL){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (parameters->util_map == NULL){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
if (df == NULL){
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
int freq = to_intconvertor(df->dpmu[0]->freq);
|
||||||
|
gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
|
||||||
|
if(parameters->util_map != NULL){
|
||||||
|
|
||||||
|
// if(parameters->g_last_image != 0){
|
||||||
|
// osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
|
||||||
|
// }
|
||||||
|
// if (freq > 300){
|
||||||
|
// 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_green_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);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
gtk_widget_queue_draw(GTK_WIDGET(parameters->util_map));
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
|
||||||
void utility_tools(GtkButton *but, gpointer udata)
|
void utility_tools(GtkButton *but, gpointer udata)
|
||||||
{
|
{
|
||||||
|
OsmGpsMap *util_map;
|
||||||
|
GtkWidget *window;
|
||||||
|
GdkPixbuf *g_red_image;
|
||||||
|
GdkPixbuf *g_green_image;
|
||||||
|
OsmGpsMapImage *g_last_image;
|
||||||
|
// -------------------
|
||||||
GtkBuilder *builder;
|
GtkBuilder *builder;
|
||||||
GError *error = NULL;
|
GError *error = NULL;
|
||||||
builder = gtk_builder_new();
|
builder = gtk_builder_new();
|
||||||
|
@ -23,6 +76,8 @@ void utility_tools(GtkButton *but, gpointer udata)
|
||||||
g_warning("%s", error->message);
|
g_warning("%s", error->message);
|
||||||
g_free(error);
|
g_free(error);
|
||||||
}
|
}
|
||||||
|
g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL);
|
||||||
|
g_green_image = gdk_pixbuf_new_from_file_at_size ("green.png", 24,24,NULL);
|
||||||
window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window"));
|
window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window"));
|
||||||
GtkContainer *map_container = GTK_CONTAINER(gtk_builder_get_object(builder, "map_layout"));
|
GtkContainer *map_container = GTK_CONTAINER(gtk_builder_get_object(builder, "map_layout"));
|
||||||
|
|
||||||
|
@ -33,14 +88,17 @@ void utility_tools(GtkButton *but, gpointer udata)
|
||||||
"tile-cache", "/tmp/",
|
"tile-cache", "/tmp/",
|
||||||
NULL);
|
NULL);
|
||||||
osm_gps_map_set_center_and_zoom (util_map, 15.4589, 75.0078, 10);
|
osm_gps_map_set_center_and_zoom (util_map, 15.4589, 75.0078, 10);
|
||||||
g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL);
|
|
||||||
g_green_image = gdk_pixbuf_new_from_file_at_size ("green.png", 24,24,NULL);
|
|
||||||
|
|
||||||
// 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.4589, 75.0078, g_red_image);
|
||||||
// g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_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};
|
||||||
|
gpointer data = (gpointer) ¶meters;
|
||||||
|
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(util_map), 600, 500);
|
||||||
|
|
||||||
gtk_container_add(map_container, GTK_WIDGET(util_map));
|
gtk_container_add(map_container, GTK_WIDGET(util_map));
|
||||||
|
g_signal_connect(window, "destroy", G_CALLBACK(gtk_widget_destroy), NULL);
|
||||||
|
|
||||||
gtk_widget_show_all(window);
|
gtk_widget_show_all(window);
|
||||||
gtk_main();
|
gtk_main();
|
||||||
|
|
|
@ -1,3 +1,4 @@
|
||||||
|
#include <stdio.h>
|
||||||
#include<gtk/gtk.h>
|
#include<gtk/gtk.h>
|
||||||
#include "osm-gps-map.h"
|
#include "osm-gps-map.h"
|
||||||
|
|
||||||
|
@ -7,10 +8,6 @@
|
||||||
#define CH_GET_WIDGET(builder, name, data) \
|
#define CH_GET_WIDGET(builder, name, data) \
|
||||||
CH_GET_OBJECT(builder, name, GTK_WIDGET, data)
|
CH_GET_OBJECT(builder, name, GTK_WIDGET, data)
|
||||||
|
|
||||||
OsmGpsMap *util_map;
|
|
||||||
GtkWidget *window;
|
|
||||||
static GdkPixbuf *g_red_image = NULL;
|
|
||||||
static GdkPixbuf *g_green_image = NULL;
|
|
||||||
static OsmGpsMapImage *g_last_image = NULL;
|
|
||||||
|
|
||||||
void utility_tools(GtkButton *but, gpointer udata);
|
void utility_tools(GtkButton *but, gpointer udata);
|
Loading…
Reference in New Issue