corrected phasor input data

This commit is contained in:
pavanvpatil 2022-10-30 00:59:41 +05:30
parent 5006efe082
commit 53c937a8e5
2 changed files with 81 additions and 47 deletions

View File

@ -12,7 +12,7 @@ struct freqlist
int idcode; int idcode;
long double AVERAGE_OF_FREQUENCY; long double AVERAGE_OF_FREQUENCY;
unsigned long long int COUNT; unsigned long long int COUNT;
struct freqlist* next; struct freqlist *next;
}; };
struct vollist struct vollist
@ -20,10 +20,9 @@ struct vollist
int idcode; int idcode;
long double AVERAGE_OF_VOLTAGE; long double AVERAGE_OF_VOLTAGE;
unsigned long long int COUNT; unsigned long long int COUNT;
struct vollist* next; struct vollist *next;
}; };
struct freqlist *head = NULL; struct freqlist *head = NULL;
struct vollist *headvol = NULL; struct vollist *headvol = NULL;
@ -34,7 +33,7 @@ gboolean attack_detect_freq(struct data_frame *df)
head = (struct freqlist *)malloc(sizeof(struct freqlist)); head = (struct freqlist *)malloc(sizeof(struct freqlist));
head->AVERAGE_OF_FREQUENCY = 50; head->AVERAGE_OF_FREQUENCY = 50;
head->COUNT = 500; head->COUNT = 500;
head->idcode=to_intconvertor(df->idcode); head->idcode = to_intconvertor(df->idcode);
return TRUE; return TRUE;
} }
else else
@ -46,10 +45,12 @@ gboolean attack_detect_freq(struct data_frame *df)
if (to_intconvertor(df->idcode) == temp->idcode) if (to_intconvertor(df->idcode) == temp->idcode)
{ {
float CURR_FREQ; float CURR_FREQ;
if (df->dpmu[0]->fmt->freq == '0'){ if (df->dpmu[0]->fmt->freq == '0')
{
CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3; CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
} }
else{ else
{
CURR_FREQ = decode_ieee_single(df->dpmu[0]->freq); CURR_FREQ = decode_ieee_single(df->dpmu[0]->freq);
} }
printf("Current freq: %f\n", CURR_FREQ); printf("Current freq: %f\n", CURR_FREQ);
@ -75,17 +76,17 @@ gboolean attack_detect_freq(struct data_frame *df)
return TRUE; return TRUE;
} }
} }
previous=temp; previous = temp;
temp=temp->next; temp = temp->next;
} }
if(temp==NULL) if (temp == NULL)
{ {
struct freqlist* bring = (struct freqlist *)malloc(sizeof(struct freqlist)); struct freqlist *bring = (struct freqlist *)malloc(sizeof(struct freqlist));
bring = (struct freqlist *)malloc(sizeof(struct freqlist)); bring = (struct freqlist *)malloc(sizeof(struct freqlist));
bring->AVERAGE_OF_FREQUENCY = 50; bring->AVERAGE_OF_FREQUENCY = 50;
bring->COUNT = 500; bring->COUNT = 500;
bring->idcode = to_intconvertor(df->idcode); bring->idcode = to_intconvertor(df->idcode);
previous->next=bring; previous->next = bring;
return TRUE; return TRUE;
} }
} }
@ -96,30 +97,48 @@ gboolean attack_detect_vol(struct data_frame *df)
float CURR_vol; float CURR_vol;
if (df->dpmu[0]->fmt->phasor == '0') if (df->dpmu[0]->fmt->phasor == '0')
{ {
unsigned char s1[2]; if (df->dpmu[0]->fmt->polar == '0')
unsigned char s2[2]; {
strncpy(s1, df->dpmu[0]->phasors[0], 2); unsigned char s1[2];
strncpy(s2, df->dpmu[0]->phasors[0] + 2, 2); unsigned char s2[2];
long double v1 = to_intconvertor(s1); strncpy(s1, df->dpmu[0]->phasors[0], 2);
long double v2 = to_intconvertor(s2); strncpy(s2, df->dpmu[0]->phasors[0] + 2, 2);
CURR_vol = sqrt((v1 * v1) + (v2 * v2)); long double v1 = to_intconvertor(s1);
long double v2 = to_intconvertor(s2);
CURR_vol = sqrt((v1 * v1) + (v2 * v2));
}
else
{
unsigned char s1[2];
strncpy(s1, df->dpmu[0]->phasors[0], 2);
CURR_vol = to_intconvertor(s1);
}
} }
else else
{ {
unsigned char s1[2]; if (df->dpmu[0]->fmt->polar == '0')
unsigned char s2[2]; {
strncpy(s1, df->dpmu[0]->phasors[0], 4); unsigned char s1[4];
strncpy(s2, df->dpmu[0]->phasors[0] + 2, 4); unsigned char s2[4];
long double v1 = decode_ieee_single(s1); strncpy(s1, df->dpmu[0]->phasors[0], 4);
long double v2 = decode_ieee_single(s2); strncpy(s2, df->dpmu[0]->phasors[0] + 2, 4);
CURR_vol = sqrt((v1 * v1) + (v2 * v2)); long double v1 = decode_ieee_single(s1);
long double v2 = decode_ieee_single(s2);
CURR_vol = sqrt((v1 * v1) + (v2 * v2));
}
else
{
unsigned char s1[4];
strncpy(s1, df->dpmu[0]->phasors[0], 4);
CURR_vol = decode_ieee_single(s1);
}
} }
if (headvol == NULL) if (headvol == NULL)
{ {
headvol = (struct vollist *)malloc(sizeof(struct vollist)); headvol = (struct vollist *)malloc(sizeof(struct vollist));
headvol->AVERAGE_OF_VOLTAGE = CURR_vol; headvol->AVERAGE_OF_VOLTAGE = CURR_vol;
headvol->COUNT = 500; headvol->COUNT = 500;
headvol->idcode=to_intconvertor(df->idcode); headvol->idcode = to_intconvertor(df->idcode);
return TRUE; return TRUE;
} }
else else
@ -174,6 +193,4 @@ gboolean attack_detect_freq_vol(struct data_frame *df)
return attack_detect_freq(df) && attack_detect_vol(df); return attack_detect_freq(df) && attack_detect_vol(df);
} }
/* pavan changes */ /* pavan changes */

View File

@ -29,7 +29,6 @@ struct DTWvollist
struct DTWvollist *next; struct DTWvollist *next;
}; };
struct DTWfreqlist *dtwhead = NULL; struct DTWfreqlist *dtwhead = NULL;
struct DTWvollist *dtwheadvol = NULL; struct DTWvollist *dtwheadvol = NULL;
@ -43,7 +42,7 @@ int DTWfreqDistance(struct data_frame *df)
dtwhead->flag = 0; dtwhead->flag = 0;
dtwhead->idcode = to_intconvertor(df->idcode); dtwhead->idcode = to_intconvertor(df->idcode);
dtwhead->next = NULL; dtwhead->next = NULL;
dtwhead->result=1; dtwhead->result = 1;
return 1; return 1;
} }
else else
@ -151,7 +150,7 @@ int DTWfreqDistance(struct data_frame *df)
bring->flag = 0; bring->flag = 0;
bring->idcode = to_intconvertor(df->idcode); bring->idcode = to_intconvertor(df->idcode);
bring->next = NULL; bring->next = NULL;
bring->result=1; bring->result = 1;
previous->next = bring; previous->next = bring;
return 1; return 1;
} }
@ -169,7 +168,7 @@ int DTWvolDistance(struct data_frame *df)
dtwheadvol->flag = 0; dtwheadvol->flag = 0;
dtwheadvol->idcode = to_intconvertor(df->idcode); dtwheadvol->idcode = to_intconvertor(df->idcode);
dtwheadvol->next = NULL; dtwheadvol->next = NULL;
dtwheadvol->result=1; dtwheadvol->result = 1;
return 1; return 1;
} }
else else
@ -183,23 +182,41 @@ int DTWvolDistance(struct data_frame *df)
float CURR_vol; float CURR_vol;
if (df->dpmu[0]->fmt->phasor == '0') if (df->dpmu[0]->fmt->phasor == '0')
{ {
unsigned char s1[2]; if (df->dpmu[0]->fmt->polar == '0')
unsigned char s2[2]; {
strncpy(s1,df->dpmu[0]->phasors[0],2); unsigned char s1[2];
strncpy(s2,df->dpmu[0]->phasors[0]+2,2); unsigned char s2[2];
long double v1 = to_intconvertor(s1); strncpy(s1, df->dpmu[0]->phasors[0], 2);
long double v2 = to_intconvertor(s2); strncpy(s2, df->dpmu[0]->phasors[0] + 2, 2);
CURR_vol = sqrt((v1*v1)+(v2*v2)); long double v1 = to_intconvertor(s1);
long double v2 = to_intconvertor(s2);
CURR_vol = sqrt((v1 * v1) + (v2 * v2));
}
else
{
unsigned char s1[2];
strncpy(s1, df->dpmu[0]->phasors[0], 2);
CURR_vol = to_intconvertor(s1);
}
} }
else else
{ {
unsigned char s1[4]; if (df->dpmu[0]->fmt->polar == '0')
unsigned char s2[4]; {
strncpy(s1,df->dpmu[0]->phasors[0],4); unsigned char s1[4];
strncpy(s2,df->dpmu[0]->phasors[0]+2,4); unsigned char s2[4];
long double v1 = decode_ieee_single(s1); strncpy(s1, df->dpmu[0]->phasors[0], 4);
long double v2 =decode_ieee_single(s2); strncpy(s2, df->dpmu[0]->phasors[0] + 2, 4);
CURR_vol = sqrt((v1*v1)+(v2*v2)); long double v1 = decode_ieee_single(s1);
long double v2 = decode_ieee_single(s2);
CURR_vol = sqrt((v1 * v1) + (v2 * v2));
}
else
{
unsigned char s1[4];
strncpy(s1, df->dpmu[0]->phasors[0], 4);
CURR_vol = decode_ieee_single(s1);
}
} }
// printf("count1: %d\ncount2: %d\n",count_track1,count_track2); // printf("count1: %d\ncount2: %d\n",count_track1,count_track2);
@ -289,7 +306,7 @@ int DTWvolDistance(struct data_frame *df)
bring->flag = 0; bring->flag = 0;
bring->idcode = to_intconvertor(df->idcode); bring->idcode = to_intconvertor(df->idcode);
bring->next = NULL; bring->next = NULL;
bring->result=1; bring->result = 1;
previous->next = bring; previous->next = bring;
return 1; return 1;
} }