2022-09-25 00:16:42 +05:30
|
|
|
/* pavan changes */
|
|
|
|
#include<time.h>
|
|
|
|
#include<stdio.h>
|
|
|
|
#include<stdlib.h>
|
|
|
|
#include "parser.h"
|
2022-09-24 16:45:28 +05:30
|
|
|
|
2022-09-25 00:16:42 +05:30
|
|
|
void attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY)
|
|
|
|
{
|
2022-09-25 16:24:02 +05:30
|
|
|
// printf("freq: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->freq)));
|
|
|
|
// printf("analog: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->analog)));
|
|
|
|
// printf("phasor %d\n",to_intconvertor(&(df->dpmu[0]->fmt->phasor)));
|
|
|
|
// printf("polar: %d\n",to_intconvertor(&(df->dpmu[0]->fmt->polar)));
|
|
|
|
|
2022-09-25 00:16:42 +05:30
|
|
|
*COUNT = *COUNT+1;
|
|
|
|
float CURR_FREQ=to_intconvertor(df->dpmu[0]->freq);
|
|
|
|
*SUM_OF_FREQUENCY+=CURR_FREQ;
|
|
|
|
float FREQ_AVG=*SUM_OF_FREQUENCY/(*COUNT*1.0f);
|
|
|
|
float DETECT_PERCENT=(abs(FREQ_AVG-CURR_FREQ)/(FREQ_AVG*1.0f))*100;
|
|
|
|
|
2022-09-25 16:24:02 +05:30
|
|
|
/* detecting based on thershold */
|
|
|
|
float THRESHOLD=70;
|
2022-09-25 00:16:42 +05:30
|
|
|
if(DETECT_PERCENT>THRESHOLD)
|
2022-09-25 16:24:02 +05:30
|
|
|
{
|
|
|
|
printf("\033[0;31m");
|
|
|
|
printf("ATTACK DETECTED!");
|
|
|
|
printf("\033[0m");
|
|
|
|
printf(" Detect_percent: %f\n",DETECT_PERCENT);
|
|
|
|
}
|
2022-09-25 00:16:42 +05:30
|
|
|
else
|
2022-09-25 16:24:02 +05:30
|
|
|
{
|
|
|
|
printf("\033[0;32m");
|
|
|
|
printf("NO PROBLEM :)\n");
|
|
|
|
printf("\033[0m");
|
|
|
|
}
|
|
|
|
|
|
|
|
/* calcculating time */
|
2022-09-25 00:16:42 +05:30
|
|
|
if(*COUNT==1)
|
|
|
|
{
|
|
|
|
time(START);
|
|
|
|
printf("entered\n");
|
|
|
|
}
|
|
|
|
time_t END;
|
|
|
|
time(&END);
|
|
|
|
double time_used = difftime(END,*START);
|
|
|
|
printf("time used %lf\n",time_used);
|
|
|
|
|
2022-09-25 16:24:02 +05:30
|
|
|
/* resetting after i minute */
|
2022-09-25 00:16:42 +05:30
|
|
|
if(time_used > 60)
|
|
|
|
{
|
|
|
|
time(START);
|
|
|
|
*SUM_OF_FREQUENCY=CURR_FREQ;
|
|
|
|
*COUNT=1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* pavan changes */
|