Compare commits

..

No commits in common. "801b369a1ad453df1434b3ebed10a5385be8b458" and "e48bdfe4c67d0ae55d28d9ab18204b791ae0cac8" have entirely different histories.

13 changed files with 71 additions and 36508 deletions

View File

@ -57,7 +57,7 @@ CLEAN_OBJECTS = $(wildcard bin/*.o) $(PROGRAM)
all: $(PROGRAM)
$(PROGRAM): $(OBJECT_FILES)
$(CC) $(CFLAGS) $(OBJECT_FILES) -o $(PROGRAM) $(LDLIBS) -lm
$(CC) $(CFLAGS) $(OBJECT_FILES) -o $(PROGRAM) $(LDLIBS)
bin/%.o: src/%.c
$(CC) $(CFLAGS) -c $< -o $@

View File

@ -169,7 +169,7 @@
</object>
</child>
<child>
<!-- n-columns=3 n-rows=2 -->
<!-- n-columns=2 n-rows=2 -->
<object class="GtkGrid">
<property name="width-request">100</property>
<property name="height-request">80</property>
@ -179,7 +179,7 @@
<property name="margin-top">10</property>
<property name="column-spacing">6</property>
<child>
<!-- n-columns=1 n-rows=9 -->
<!-- n-columns=1 n-rows=5 -->
<object class="GtkGrid">
<property name="width-request">80</property>
<property name="visible">True</property>
@ -187,7 +187,7 @@
<property name="row-spacing">35</property>
<child>
<object class="GtkButton" id="voltage">
<property name="label" translatable="yes">Voltage Magnitude</property>
<property name="label" translatable="yes">Voltage</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
@ -218,7 +218,7 @@
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">3</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
@ -227,14 +227,13 @@
<property name="can-focus">False</property>
<property name="active">0</property>
<items>
<item id="0" translatable="yes">Gaussian</item>
<item id="1" translatable="yes">kmeans</item>
<item translatable="yes">DTW</item>
<item id="0" translatable="yes">kmeans</item>
<item id="1" translatable="yes">simple</item>
</items>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">5</property>
<property name="top-attach">3</property>
</packing>
</child>
<child>
@ -244,52 +243,15 @@
<property name="active">0</property>
<items>
<item id="0" translatable="yes">frequency only</item>
<item id="1" translatable="yes">voltage only</item>
<item id="2" translatable="yes">frequency,voltage</item>
<item id="1" translatable="yes">frequency,voltage</item>
<item id="2" translatable="yes">voltage</item>
</items>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">7</property>
</packing>
</child>
<child>
<object class="GtkButton" id="dfreq">
<property name="label" translatable="yes">dfreq</property>
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">2</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="algo_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Algorithm</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">4</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="dimm_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Dimmensions</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">6</property>
</packing>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">0</property>
@ -319,202 +281,6 @@
<property name="top-attach">1</property>
</packing>
</child>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Legend</property>
<property name="use-markup">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="title" translatable="yes">red</property>
<property name="rgba">rgb(238,29,0)</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel" id="legend_label">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Attack/Event</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="rgba">rgb(0,255,0)</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Normal</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<placeholder/>
</child>
<child>
<placeholder/>
</child>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkScrolledWindow">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="shadow-type">in</property>
<child>
<object class="GtkViewport">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkBox">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="orientation">vertical</property>
<child>
<object class="GtkLabel" id="graph_legend1">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Graph Legend</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">0</property>
</packing>
</child>
<child>
<!-- n-columns=2 n-rows=1 -->
<object class="GtkGrid">
<property name="visible">True</property>
<property name="can-focus">False</property>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
<property name="rgba">rgb(255,120,0)</property>
</object>
<packing>
<property name="left-attach">0</property>
<property name="top-attach">0</property>
</packing>
</child>
<child>
<object class="GtkLabel">
<property name="visible">True</property>
<property name="can-focus">False</property>
<property name="label" translatable="yes">Pmu</property>
</object>
<packing>
<property name="left-attach">1</property>
<property name="top-attach">0</property>
</packing>
</child>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">1</property>
</packing>
</child>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">2</property>
</packing>
</child>
<child>
<object class="GtkColorButton">
<property name="visible">True</property>
<property name="can-focus">True</property>
<property name="receives-default">True</property>
</object>
<packing>
<property name="expand">False</property>
<property name="fill">True</property>
<property name="position">3</property>
</packing>
</child>
</object>
</child>
</object>
</child>
</object>
<packing>
<property name="left-attach">2</property>
<property name="top-attach">1</property>
</packing>
</child>
<child>
<placeholder/>
</child>

View File

@ -2,7 +2,10 @@
#include <time.h>
#include <gtk/gtk.h>
/* variables declared of attack_detect function */
float SUM_OF_FREQUENCY=0;
float COUNT=0;
time_t START;
/* function declared */
gboolean attack_detect(struct data_frame *df);
gboolean attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY);
/* pavan changes */

View File

@ -1,5 +0,0 @@
/*pavan changes*/
int DTWfreqDistance(struct data_frame *df);
int DTWvolDistance(struct data_frame *df);

View File

@ -1,10 +0,0 @@
/*Pavan Changes*/
#include <gtk/gtk.h>
// intial variables
//function declaration
gboolean kmeans(struct data_frame *df);
/*Pavan Changes*/

View File

@ -8,15 +8,5 @@ typedef struct{
int current_selection;
} myParameters;
struct vis_data{
int id;
float lat;
float lon;
GdkPixbuf *last_image;
GTimeVal last_update_time;
struct vis_data *next;
};
struct vis_data *head;
gboolean update_images(gpointer* pars);

View File

@ -1,29 +0,0 @@
import csv
import pandas as pd
import matplotlib.pyplot as plt
x=[]
y=[]
x1=[]
y1=[]
x2=[]
y2=[]
with open('points.csv', mode ='r') as file:
csvFile = csv.reader(file)
for lines in csvFile:
print(lines)
x.append(float(lines[0]))
y.append(0)
x1.append(float(lines[1]))
y1.append(0)
x2.append(float(lines[2]))
y2.append(0)
plt.scatter(x, y)
plt.scatter(x1, y1)
plt.scatter(x2,y2)
plt.show()

File diff suppressed because it is too large Load Diff

View File

@ -3,37 +3,58 @@
#include<stdio.h>
#include<stdlib.h>
#include<gtk/gtk.h>
#include <math.h>
#include "parser.h"
long double AVERAGE_OF_FREQUENCY = 50;
unsigned long long int COUNT = 500;
gboolean attack_detect(struct data_frame *df)
gboolean attack_detect(struct data_frame *df,time_t* START,float* COUNT,float* SUM_OF_FREQUENCY)
{
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;
// 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)));
/* detecting based on thershold frequency can vary only around 0.2 hz*/
if (DETECT_PERCENT > 0.9)
*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;
gboolean detect;
/* detecting based on thershold */
float THRESHOLD=60;
if(DETECT_PERCENT>THRESHOLD)
{
detect=FALSE;
printf("\033[0;31m");
printf("ATTACK DETECTED!");
printf("\033[0m");
return FALSE;
// intf(" Detect_percent: %f\n",DETECT_PERCENT);
}
else
{
detect=TRUE;
printf("\033[0;32m");
printf("NO PROBLEM :)\n");
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;
}
/* calcculating time */
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);
/* resetting after i minute */
if(time_used > 60)
{
time(START);
*SUM_OF_FREQUENCY=CURR_FREQ;
*COUNT=1;
}
return detect;
}
/* pavan changes */

View File

@ -1,298 +0,0 @@
#include "parser.h"
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <gtk/gtk.h>
#include <stdlib.h>
struct DTWfreqlist
{
int idcode;
long double *freq1;
long double *freq2;
int count_track1;
int count_track2;
int flag;
int result;
struct DTWfreqlist *next;
};
struct DTWvollist
{
int idcode;
long double *vol1;
long double *vol2;
int count_track1;
int count_track2;
int flag;
int result;
struct DTWvollist *next;
};
struct DTWfreqlist *head = NULL;
struct DTWvollist *headvol = NULL;
int DTWfreqDistance(struct data_frame *df)
{
if (head == NULL)
{
head = (struct DTWfreqlist *)malloc(sizeof(struct DTWfreqlist));
head->count_track1 = 0;
head->count_track2 = 0;
head->flag = 0;
head->idcode = to_intconvertor(df->idcode);
head->next = NULL;
head->result=1;
return 1;
}
else
{
struct DTWfreqlist *temp = head;
struct DTWfreqlist *previous;
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("count1: %d\ncount2: %d\n",count_track1,count_track2);
// printf("curr_freq: %f\n",CURR_FREQ);
if (temp->count_track1 == 0)
{
if (temp->flag == 0)
{
temp->flag = 1;
temp->freq1 = (long double *)malloc(500 * sizeof(long double));
}
temp->freq1[temp->count_track2] = CURR_FREQ;
temp->count_track2++;
if (temp->count_track2 == 500)
{
temp->count_track2 = 0;
temp->flag = 0;
temp->count_track1++;
}
}
else if (temp->count_track1 == 1)
{
if (temp->flag == 0)
{
temp->flag = 1;
temp->freq2 = (long double *)malloc(500 * sizeof(long double));
}
temp->freq2[temp->count_track2] = CURR_FREQ;
temp->count_track2++;
if (temp->count_track2 == 500)
{
temp->count_track2 = 0;
temp->flag = 0;
temp->count_track1++;
}
}
else
{
float **DTW = (float **)malloc(501 * sizeof(float *));
for (int i = 0; i < 501; i++)
DTW[i] = (float *)malloc(501 * sizeof(float));
for (int i = 0; i < 501; i++)
{
for (int j = 0; j < 501; j++)
DTW[i][j] = 1000;
}
DTW[0][0] = 0;
for (int i = 1; i < 501; i++)
{
for (int j = 1; j < 501; j++)
{
float cost = fabs(temp->freq1[i - 1] - temp->freq2[j - 1]);
// printf("cost: %f",cost);
DTW[i][j] = cost + fmin(DTW[i][j - 1], fmin(DTW[i - 1][j], DTW[i - 1][j - 1]));
// printf(" DTW[%d][%d]: %f\n",i,j,DTW[i][j]);
}
}
printf("DTWdistance: %f\n", DTW[500][500]);
if (DTW[500][500] >= 35)
{
free(temp->freq2);
temp->result = 0;
}
else
{
long double *f = temp->freq1;
temp->freq1 = temp->freq2;
free(f);
temp->result = 1;
}
free(DTW);
temp->count_track1 = 1;
}
break;
}
previous = temp;
temp = temp->next;
}
if (temp == NULL)
{
struct DTWfreqlist *bring = (struct DTWfreqlist *)malloc(sizeof(struct DTWfreqlist));
bring->count_track1 = 0;
bring->count_track2 = 0;
bring->flag = 0;
bring->idcode = to_intconvertor(df->idcode);
bring->next = NULL;
bring->result=1;
previous->next = bring;
return 1;
}
return temp->result;
}
}
int DTWvolDistance(struct data_frame *df)
{
if (headvol == NULL)
{
headvol = (struct DTWvollist *)malloc(sizeof(struct DTWvollist));
headvol->count_track1 = 0;
headvol->count_track2 = 0;
headvol->flag = 0;
headvol->idcode = to_intconvertor(df->idcode);
headvol->next = NULL;
headvol->result=1;
return 1;
}
else
{
struct DTWvollist *temp = headvol;
struct DTWvollist *previous;
while (temp != NULL)
{
if (to_intconvertor(df->idcode) == temp->idcode)
{
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[4];
unsigned char s2[4];
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));
}
// printf("count1: %d\ncount2: %d\n",count_track1,count_track2);
// printf("curr_vol: %f\n",CURR_vol);
if (temp->count_track1 == 0)
{
if (temp->flag == 0)
{
temp->flag = 1;
temp->vol1 = (long double *)malloc(500 * sizeof(long double));
}
temp->vol1[temp->count_track2] = CURR_vol;
temp->count_track2++;
if (temp->count_track2 == 500)
{
temp->count_track2 = 0;
temp->flag = 0;
temp->count_track1++;
}
}
else if (temp->count_track1 == 1)
{
if (temp->flag == 0)
{
temp->flag = 1;
temp->vol2 = (long double *)malloc(500 * sizeof(long double));
}
temp->vol2[temp->count_track2] = CURR_vol;
temp->count_track2++;
if (temp->count_track2 == 500)
{
temp->count_track2 = 0;
temp->flag = 0;
temp->count_track1++;
}
}
else
{
float **DTW = (float **)malloc(501 * sizeof(float *));
for (int i = 0; i < 501; i++)
DTW[i] = (float *)malloc(501 * sizeof(float));
for (int i = 0; i < 501; i++)
{
for (int j = 0; j < 501; j++)
DTW[i][j] = 1000;
}
DTW[0][0] = 0;
for (int i = 1; i < 501; i++)
{
for (int j = 1; j < 501; j++)
{
float cost = fabs(temp->vol1[i - 1] - temp->vol2[j - 1]);
// printf("cost: %f",cost);
DTW[i][j] = cost + fmin(DTW[i][j - 1], fmin(DTW[i - 1][j], DTW[i - 1][j - 1]));
// printf(" DTW[%d][%d]: %f\n",i,j,DTW[i][j]);
}
}
printf("DTWdistance: %f\n", DTW[500][500]);
if (DTW[500][500] >= 35)
{
free(temp->vol2);
temp->result = 0;
}
else
{
long double *f = temp->vol1;
temp->vol1 = temp->vol2;
free(f);
temp->result = 1;
}
free(DTW);
temp->count_track1 = 1;
}
break;
}
previous = temp;
temp = temp->next;
}
if (temp == NULL)
{
struct DTWvollist *bring = (struct DTWvollist *)malloc(sizeof(struct DTWvollist));
bring->count_track1 = 0;
bring->count_track2 = 0;
bring->flag = 0;
bring->idcode = to_intconvertor(df->idcode);
bring->next = NULL;
bring->result=1;
previous->next = bring;
return 1;
}
return temp->result;
}
}

View File

@ -1,59 +0,0 @@
/*Pavan Changes*/
#include "parser.h"
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <math.h>
FILE *fp;
/*intial weights weights for each points */
unsigned long long int count_A = 1000;
unsigned long long int count_B = 1000;
unsigned long long int count_C = 1000;
/*In India frequency ranges from 49.5 to 50.2 Hz*/
long double std_dev = 0.6454972244;
long double A = 0; // for point A=50
long double B = -1.5491933394; // for point B=49
long double C = 0.7745966692; // for point C=50.5
long double mean = 50;
unsigned long long int count = 3000;
gboolean kmeans(struct data_frame *df)
{
long double CURR_FREQ = 50 + to_intconvertor(df->dpmu[0]->freq) * 1e-3;
long double CURR_FREQ_temp = CURR_FREQ;
CURR_FREQ = (CURR_FREQ - mean) / std_dev;
long double diff_A = fabs(A - CURR_FREQ);
long double diff_B = fabs(B - CURR_FREQ);
long double diff_C = fabs(C - CURR_FREQ);
// fp = fopen("points.csv","a");
// printf("A: %Lf, B: %Lf, C: %Lf\n",A,B,C);
// fprintf(fp,"%Lf, %Lf, %Lf\n",A,B,C);
// fclose(fp);
/*Updating std_dev and mean*/
// printf("std_dev: %Lf, mean: %Lf\n",std_dev,mean);
mean = ((mean * count) + CURR_FREQ_temp) / (++count);
std_dev = (((std_dev * std_dev) * (count - 1)) + (CURR_FREQ * std_dev * CURR_FREQ * std_dev)) / count;
std_dev = sqrt(std_dev);
if (diff_A <= diff_B && diff_A <= diff_C)
{
A = ((count_A * (A)) + CURR_FREQ) / (++count_A);
return TRUE;
}
else if (diff_B < diff_C)
{
B = ((count_B * (B)) + CURR_FREQ) / (++count_B);
return FALSE;
}
else
{
C = ((count_C * (C)) + CURR_FREQ) / (++count_C);
return FALSE;
}
}
/*Pavan Changes*/

View File

@ -1,6 +1,4 @@
#include <stdlib.h>
#include <stdio.h>
#include <gtk/gtk.h>
#include <pthread.h>
#include "global.h"
#include "align_sort.h"
@ -8,8 +6,6 @@
#include "parser.h"
#include "osm-gps-map.h"
#include "Attack_detect.h"
#include "Kmeans.h"
#include "Dynamic_time_warping.h"
#include "connections.h"
#include "livechart.h"
#include "utility_tools.h"
@ -30,66 +26,46 @@ gboolean update_images(gpointer* pars){
if (df == NULL){
return TRUE;
}
//int freq = to_intconvertor(df->dpmu[0]->freq);
//gboolean green =attack_detect(df);
//printf("map_vis A: %Lf, B: %Lf,C: %Lf\n",A,B,C);
//gboolean green = kmeans(df);
if (curr_measurement==0)
{
int i = 0, k = 0;
float freq,vol_magnitude,angle, dfreq;
unsigned char freq_fmt, anal_fmt, phas_fmt, polar_fmt;
float freq;
unsigned char fmt;
while (df!=NULL){
float lat;
float lon;
loops++;
// printf("loops: %d\n", loops);
printf("loops: %d\n", loops);
id = to_intconvertor(df->idcode);
// printf("id = %d\n",id);
printf("id = %d\n",id);
pthread_mutex_lock(&mutex_cfg);
temp_cfg = cfgfirst;
// Check for the IDCODE in Configuration Frame
while(temp_cfg != NULL){
if(id == to_intconvertor(temp_cfg->idcode)){
cfg_match = 1;
// printf("Matched - id : %d\n",id);
freq_fmt = temp_cfg->pmu[0]->fmt->freq;
anal_fmt = temp_cfg->pmu[0]->fmt->analog;
phas_fmt = temp_cfg->pmu[0]->fmt->phasor;
polar_fmt = temp_cfg->pmu[0]->fmt->polar;
printf("Matched - id : %d\n",id);
fmt = temp_cfg->pmu[0]->fmt->freq;
break;
} else {
temp_cfg = temp_cfg->cfgnext;
}
}
pthread_mutex_unlock(&mutex_cfg);
// get data from df.
if(freq_fmt == '1'){
if(fmt == '1'){
freq = decode_ieee_single(df->dpmu[i]->freq);
// printf("freq = %f\n",freq);
printf("freq = %f\n",freq);
}else{
freq = to_intconvertor(df->dpmu[i]->freq)*1e-6+50;
}
unsigned char first2bytes[2];
strncpy(first2bytes, df->dpmu[i]->phasors[0], 2);
unsigned char last2bytes[2];
strncpy(last2bytes, df->dpmu[i]->phasors[0]+2, 2);
vol_magnitude = to_intconvertor(first2bytes);
float imaginary = to_intconvertor(last2bytes);
// printf("vol = %f imag = %f\n",vol_magnitude, imaginary);
live_chart_serie_add(serie, freq);
// check lower layer details to get longitude and lattitude.
pthread_mutex_lock(&mutex_Lower_Layer_Details);
LLptr = LLfirst;
match = 0;
while(LLptr != NULL){
// printf("pmuid = %d\n",LLptr->pmuid);
printf("pmuid = %d\n",LLptr->pmuid);
if(LLptr->pmuid == id){
match = 1;
float lat = LLptr->latitude;
@ -100,17 +76,18 @@ gboolean update_images(gpointer* pars){
}
pthread_mutex_unlock(&mutex_Lower_Layer_Details);
// if(match == 1 && cfg_match == 1){
// printf("lat = %f, lon = %f, freq = %f\n",lat,lon,freq);
if(match == 1 && cfg_match == 1){
printf("lat = %f, lon = %f, freq = %f\n",lat,lon,freq);
gboolean green =attack_detect(df,&START,&COUNT,&SUM_OF_FREQUENCY);
if(parameters->g_last_image != 0){
osm_gps_map_image_remove(parameters->util_map, parameters->g_last_image);
}
if (DTWvolDistance(df)){
if (freq > 50.300){
parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_green_image);
}else{
parameters->g_last_image = osm_gps_map_image_add(parameters->util_map,lat, lon, parameters->g_red_image);
}
// }
}
df = df->dnext;
// i++;
k++;

View File

@ -105,15 +105,12 @@ void utility_tools(GtkButton *but, gpointer udata)
"map-source", OSM_GPS_MAP_SOURCE_OSMC_TRAILS,
"tile-cache", "/tmp/",
NULL);
// TODO: centering the map
osm_gps_map_set_center_and_zoom(utdata->util_map, 15.4589, 75.0078, 10);
// TODO: add the points to window.
g_last_image = osm_gps_map_image_add(utdata->util_map, 15.4589, 75.0078, g_red_image);
g_last_image = osm_gps_map_image_add(utdata->util_map, 15.518597, 74.925584, g_green_image);
curr_measurement = 0;
algorithm = 0;
dimmension = 0;
@ -156,11 +153,6 @@ void utility_tools(GtkButton *but, gpointer udata)
g_signal_connect(utdata->util_window, "destroy", G_CALLBACK(on_window_destroy), GUINT_TO_POINTER(pid));
// //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(utdata->util_map,15.518597, 74.925584, g_green_image);
// myParameters parameters = {utdata->util_map, g_red_image, g_green_image, g_last_image};
// gpointer data = (gpointer) &parameters;
// guint pid = g_timeout_add(20, (GSourceFunc) update_images, data);
// gtk_widget_set_vexpand(GTK_WIDGET(utdata->util_map), TRUE);
// gtk_widget_set_hexpand(GTK_WIDGET(utdata->util_map), TRUE);
gtk_widget_show_all(utdata->util_window);