iPDC-suite/iPDC/src/Attack_detect.c

39 lines
1.0 KiB
C
Raw Normal View History

2022-09-25 00:16:42 +05:30
/* pavan changes */
2022-10-25 23:58:31 +05:30
#include <time.h>
#include <stdio.h>
#include <stdlib.h>
#include <gtk/gtk.h>
#include <math.h>
2022-09-25 00:16:42 +05:30
#include "parser.h"
2022-09-24 16:45:28 +05:30
2022-10-25 23:58:31 +05:30
long double AVERAGE_OF_FREQUENCY = 50;
unsigned long long int COUNT = 500;
gboolean attack_detect(struct data_frame *df)
2022-09-25 00:16:42 +05:30
{
2022-10-25 23:58:31 +05:30
float CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
printf("Current freq: %f\n", CURR_FREQ);
float DETECT_PERCENT = (fabs(AVERAGE_OF_FREQUENCY - CURR_FREQ) / (AVERAGE_OF_FREQUENCY * 1.0f)) * 100;
2022-09-25 16:24:02 +05:30
2022-10-25 23:58:31 +05:30
/* detecting based on thershold frequency can vary only around 0.2 hz*/
if (DETECT_PERCENT > 0.9)
2022-09-25 16:24:02 +05:30
{
printf("\033[0;31m");
printf("ATTACK DETECTED!");
printf("\033[0m");
2022-10-25 23:58:31 +05:30
return FALSE;
2022-09-25 16:24:02 +05:30
}
2022-10-25 23:58:31 +05:30
else
2022-09-25 16:24:02 +05:30
{
printf("\033[0;32m");
printf("NO PROBLEM :)\n");
2022-10-25 23:58:31 +05:30
printf("\033[0m");
/* updating mean of frequency */
AVERAGE_OF_FREQUENCY = ((AVERAGE_OF_FREQUENCY * COUNT) + CURR_FREQ) / ++COUNT;
printf("avg freq: %Lf\n", AVERAGE_OF_FREQUENCY);
return TRUE;
2022-09-25 00:16:42 +05:30
}
}
/* pavan changes */