AlGO DONE FOR GAUSSIAN
This commit is contained in:
parent
25dfbc2444
commit
b10a48516c
|
@ -1,8 +1,8 @@
|
||||||
/* pavan changes */
|
/* pavan changes */
|
||||||
#include <time.h>
|
|
||||||
#include <gtk/gtk.h>
|
#include <gtk/gtk.h>
|
||||||
/* variables declared of attack_detect function */
|
/* variables declared of attack_detect function */
|
||||||
|
|
||||||
/* function declared */
|
/* function declared */
|
||||||
gboolean attack_detect(struct data_frame *df);
|
gboolean attack_detect_freq(struct data_frame *df);
|
||||||
|
gboolean attack_detect_vol(struct data_frame *df)
|
||||||
/* pavan changes */
|
/* pavan changes */
|
|
@ -6,34 +6,161 @@
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include "parser.h"
|
#include "parser.h"
|
||||||
|
|
||||||
long double AVERAGE_OF_FREQUENCY = 50;
|
struct freqlist
|
||||||
unsigned long long int COUNT = 500;
|
|
||||||
|
|
||||||
gboolean attack_detect(struct data_frame *df)
|
|
||||||
{
|
{
|
||||||
float CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
|
int idcode;
|
||||||
printf("Current freq: %f\n", CURR_FREQ);
|
long double AVERAGE_OF_FREQUENCY;
|
||||||
float DETECT_PERCENT = (fabs(AVERAGE_OF_FREQUENCY - CURR_FREQ) / (AVERAGE_OF_FREQUENCY * 1.0f)) * 100;
|
unsigned long long int COUNT;
|
||||||
|
struct freqlist* next;
|
||||||
|
};
|
||||||
|
|
||||||
/* detecting based on thershold frequency can vary only around 0.2 hz*/
|
struct vollist
|
||||||
if (DETECT_PERCENT > 0.9)
|
{
|
||||||
|
int idcode;
|
||||||
|
long double AVERAGE_OF_VOLTAGE;
|
||||||
|
unsigned long long int COUNT;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
struct freqlist *head = NULL;
|
||||||
|
struct vollist *headvol = NULL
|
||||||
|
|
||||||
|
gboolean attack_detect_freq(struct data_frame *df)
|
||||||
|
{
|
||||||
|
if (head == NULL)
|
||||||
{
|
{
|
||||||
printf("\033[0;31m");
|
head = (struct freqlist *)malloc(sizeof(struct freqlist));
|
||||||
printf("ATTACK DETECTED!");
|
head->AVERAGE_OF_FREQUENCY = 50;
|
||||||
printf("\033[0m");
|
head->COUNT = 500;
|
||||||
return FALSE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
printf("\033[0;32m");
|
struct freqlist *temp = head;
|
||||||
printf("NO PROBLEM :)\n");
|
struct freqlist *previous = NULL;
|
||||||
printf("\033[0m");
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
if (to_intconvertor(df->idcode) == temp->idcode)
|
||||||
|
{
|
||||||
|
float CURR_FREQ;
|
||||||
|
if (df->dpmu[0]->fmt->freq == '0'){
|
||||||
|
CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
CURR_FREQ = decode_ieee_single(df->dpmu[0]->freq);
|
||||||
|
}
|
||||||
|
printf("Current freq: %f\n", CURR_FREQ);
|
||||||
|
float DETECT_PERCENT = (fabs(temp->AVERAGE_OF_FREQUENCY - CURR_FREQ) / (temp->AVERAGE_OF_FREQUENCY * 1.0f)) * 100;
|
||||||
|
|
||||||
/* updating mean of frequency */
|
/* detecting based on thershold frequency can vary only around 0.2 hz*/
|
||||||
AVERAGE_OF_FREQUENCY = ((AVERAGE_OF_FREQUENCY * COUNT) + CURR_FREQ) / ++COUNT;
|
if (DETECT_PERCENT > 0.9)
|
||||||
printf("avg freq: %Lf\n", AVERAGE_OF_FREQUENCY);
|
{
|
||||||
|
printf("\033[0;31m");
|
||||||
|
printf("ATTACK DETECTED!");
|
||||||
|
printf("\033[0m");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\033[0;32m");
|
||||||
|
printf("NO PROBLEM :)\n");
|
||||||
|
printf("\033[0m");
|
||||||
|
|
||||||
|
/* updating mean of frequency */
|
||||||
|
temp->AVERAGE_OF_FREQUENCY = ((temp->AVERAGE_OF_FREQUENCY * temp->COUNT) + CURR_FREQ) / ++temp->COUNT;
|
||||||
|
printf("avg freq: %Lf\n", temp->AVERAGE_OF_FREQUENCY);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previous=temp;
|
||||||
|
temp=temp->next;
|
||||||
|
}
|
||||||
|
if(temp==NULL)
|
||||||
|
{
|
||||||
|
struct freqlist* bring = (struct freqlist *)malloc(sizeof(struct freqlist));
|
||||||
|
bring = (struct freqlist *)malloc(sizeof(struct freqlist));
|
||||||
|
bring->AVERAGE_OF_FREQUENCY = 50;
|
||||||
|
bring->COUNT = 500;
|
||||||
|
previous->next=bring;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
gboolean attack_detect_vol(struct data_frame *df)
|
||||||
|
{
|
||||||
|
float CURR_vol;
|
||||||
|
if (df->dpmu[0]->fmt->phasor == '0')
|
||||||
|
{
|
||||||
|
unsigned char s1[2];
|
||||||
|
unsigned char s2[2];
|
||||||
|
strncpy(s1, df->dpmu[0]->phasors[0], 2);
|
||||||
|
strncpy(s2, df->dpmu[0]->phasors[0] + 2, 2);
|
||||||
|
long double v1 = to_intconvertor(s1);
|
||||||
|
long double v2 = to_intconvertor(s2);
|
||||||
|
CURR_vol = sqrt((v1 * v1) + (v2 * v2));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
unsigned char s1[2];
|
||||||
|
unsigned char s2[2];
|
||||||
|
strncpy(s1, df->dpmu[0]->phasors[0], 4);
|
||||||
|
strncpy(s2, df->dpmu[0]->phasors[0] + 2, 4);
|
||||||
|
long double v1 = decode_ieee_single(s1);
|
||||||
|
long double v2 = decode_ieee_single(s2);
|
||||||
|
CURR_vol = sqrt((v1 * v1) + (v2 * v2));
|
||||||
|
}
|
||||||
|
if (head == NULL)
|
||||||
|
{
|
||||||
|
head = (struct vollist *)malloc(sizeof(struct vollist));
|
||||||
|
head->AVERAGE_OF_VOLTAGE = CURR_vol;
|
||||||
|
head->COUNT = 500;
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
struct vollist *temp = head;
|
||||||
|
struct vollist *previous = NULL;
|
||||||
|
while (temp != NULL)
|
||||||
|
{
|
||||||
|
if (to_intconvertor(df->idcode) == temp->idcode)
|
||||||
|
{
|
||||||
|
printf("Current vol: %f\n", CURR_vol);
|
||||||
|
float DETECT_PERCENT = (fabs(temp->AVERAGE_OF_VOLTAGE - CURR_vol) / (temp->AVERAGE_OF_VOLTAGE * 1.0f)) * 100;
|
||||||
|
|
||||||
|
/* detecting based on thershold VOLTAGE can vary only around 0.2 hz*/
|
||||||
|
if (DETECT_PERCENT > 5)
|
||||||
|
{
|
||||||
|
printf("\033[0;31m");
|
||||||
|
printf("ATTACK DETECTED!");
|
||||||
|
printf("\033[0m");
|
||||||
|
return FALSE;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
printf("\033[0;32m");
|
||||||
|
printf("NO PROBLEM :)\n");
|
||||||
|
printf("\033[0m");
|
||||||
|
|
||||||
|
/* updating mean of VOLTAGE */
|
||||||
|
temp->AVERAGE_OF_VOLTAGE = ((temp->AVERAGE_OF_VOLTAGE * temp->COUNT) + CURR_vol) / ++temp->COUNT;
|
||||||
|
printf("avg vol: %Lf\n", temp->AVERAGE_OF_VOLTAGE);
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
previous = temp;
|
||||||
|
temp = temp->next;
|
||||||
|
}
|
||||||
|
if (temp == NULL)
|
||||||
|
{
|
||||||
|
struct vollist *bring = (struct vollist *)malloc(sizeof(struct vollist));
|
||||||
|
bring = (struct vollist *)malloc(sizeof(struct vollist));
|
||||||
|
bring->AVERAGE_OF_VOLTAGE = CURR_vol;
|
||||||
|
bring->COUNT = 500;
|
||||||
|
previous->next = bring;
|
||||||
|
return TRUE;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/* pavan changes */
|
/* pavan changes */
|
Loading…
Reference in New Issue