diff --git a/iPDC/align_sort.c b/iPDC/align_sort.c index 78aaa64..9ad1197 100755 --- a/iPDC/align_sort.c +++ b/iPDC/align_sort.c @@ -296,22 +296,17 @@ void assign_df_to_TSB(struct data_frame *df,int index) { void dispatch(int index) { - int size,flag = 0; + int size; sort_data_inside_TSB(index); dataframe = NULL; pthread_mutex_lock(&mutex_Upper_Layer_Details); struct Upper_Layer_Details *temp_pdc = ULfirst; + size = create_dataframe(index); while(temp_pdc != NULL ) { if((temp_pdc->UL_upper_pdc_cfgsent == 1) && (temp_pdc->UL_data_transmission_off == 0)) { - if(flag == 0) { - - size = create_dataframe(index); - flag = 1; - } - if(temp_pdc->config_change == 1) { dataframe[14] = 0x04; diff --git a/iPDC/green.png b/iPDC/green.png new file mode 100644 index 0000000..9c868c6 Binary files /dev/null and b/iPDC/green.png differ diff --git a/iPDC/ipdcGui.c b/iPDC/ipdcGui.c index 4cf498b..2e81114 100755 --- a/iPDC/ipdcGui.c +++ b/iPDC/ipdcGui.c @@ -2182,12 +2182,13 @@ void ipdc_setup_fileSelector (GtkWidget *widget, gpointer udata) NULL); res = gtk_dialog_run(GTK_DIALOG(ipdc_setup_window)); + printf("res = %d", res); if(res == GTK_RESPONSE_ACCEPT) { char *filename; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(ipdc_setup_window)); - strcpy(ipdcFilePath, filename); + g_print("File selected: %s\n", filename); view_setup_file(filename); g_free(filename); } @@ -2224,7 +2225,7 @@ void view_setup_file (char *filename) gtk_widget_destroy(ipdc_setup_window); - fp1 = fopen(s, "rb"); + fp1 = fopen(filename, "rb"); if (fp1 == NULL) { @@ -2279,7 +2280,7 @@ void view_setup_file (char *filename) fclose (fp1); /* Open the iPDC Setup File in read mode */ - fp1 = fopen(s, "rb"); + fp1 = fopen(filename, "rb"); /* If its available, then create a new dialog window for displaying the iPDC details. */ setup_display_window = gtk_dialog_new (); @@ -2296,7 +2297,7 @@ void view_setup_file (char *filename) gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_NEVER, GTK_POLICY_AUTOMATIC); /* The dialog window is created with a vbox packed into it */ - gtk_box_pack_start (GTK_BOX (GTK_DIALOG(setup_display_window)), scrolled_window, TRUE, TRUE, 0); + gtk_box_pack_start (gtk_dialog_get_content_area(setup_display_window), scrolled_window, TRUE, TRUE, 0); gtk_widget_show (scrolled_window); /* Create a table of ? by 2 squares */ @@ -2543,8 +2544,8 @@ void view_setup_file (char *filename) /* This makes it so the ok_button is the default. */ gtk_widget_set_can_default (cancel_button, TRUE); gtk_widget_set_can_default (apply_button, TRUE); - gtk_box_pack_start (gtk_dialog_get_action_area, apply_button, TRUE, TRUE, 0); - gtk_box_pack_start (gtk_dialog_get_action_area, cancel_button, TRUE, TRUE, 0); + gtk_box_pack_start (gtk_dialog_get_action_area(setup_display_window), apply_button, TRUE, TRUE, 0); + gtk_box_pack_start (gtk_dialog_get_action_area(setup_display_window), cancel_button, TRUE, TRUE, 0); /* This grabs this button to be the default button. Simply hitting the "Enter" key will cause this button to activate. */ gtk_widget_grab_default (cancel_button); diff --git a/iPDC/new_pmu_or_pdc.c b/iPDC/new_pmu_or_pdc.c index 1910e84..b0cb390 100755 --- a/iPDC/new_pmu_or_pdc.c +++ b/iPDC/new_pmu_or_pdc.c @@ -319,10 +319,10 @@ void* connect_pmu_tcp(void *temp) { continue; } - if (sendto(DB_sockfd,tcp_BUF, MAXBUFLEN-1, 0, - (struct sockaddr *)&DB_Server_addr,sizeof(DB_Server_addr)) == -1) { - perror("sendto"); - } + // if (sendto(DB_sockfd,tcp_BUF, MAXBUFLEN-1, 0, + // (struct sockaddr *)&DB_Server_addr,sizeof(DB_Server_addr)) == -1) { + // perror("sendto"); + // } tcp_BUF[bytes_read] = '\0'; PMU_process_TCP(tcp_BUF,tcp_sockfd); diff --git a/iPDC/parser.c b/iPDC/parser.c index dd6793d..a28d22f 100755 --- a/iPDC/parser.c +++ b/iPDC/parser.c @@ -60,7 +60,7 @@ #include "align_sort.h" #include "connections.h" #include "recreate.h" - +#include "utility_tools.h" /* ---------------------------------------------------------------------------- */ /* FUNCTION cfgparser(): */ @@ -1269,6 +1269,23 @@ int dataparser(unsigned char data[]) { //No match for configuration frame printf("Configuration is not fresent for received data frame!\n"); } + printf("freq = %d\n",to_intconvertor(df->dpmu[0]->freq)); + // temp code + int freq = to_intconvertor(df->dpmu[0]->freq); + if(util_map != NULL){ + g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL); + g_green_image = gdk_pixbuf_new_from_file_at_size ("green.png", 24,24,NULL); + if(g_last_image != 0){ + osm_gps_map_image_remove(util_map, g_last_image); + } + if (freq > 300){ + g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image); + }else{ + g_last_image = osm_gps_map_image_add(util_map,15.518597, 74.925584, g_green_image); + } + gtk_widget_show_all(GTK_WIDGET(util_map)); + + } if((config_change == 14) ||(config_change == 10)) return config_change; diff --git a/iPDC/poi.png b/iPDC/poi.png new file mode 100644 index 0000000..4ab54c9 Binary files /dev/null and b/iPDC/poi.png differ diff --git a/iPDC/red.png b/iPDC/red.png new file mode 100644 index 0000000..91edd7c Binary files /dev/null and b/iPDC/red.png differ diff --git a/iPDC/utility_tools.c b/iPDC/utility_tools.c index 1071c33..26c2e62 100644 --- a/iPDC/utility_tools.c +++ b/iPDC/utility_tools.c @@ -1,8 +1,18 @@ #include -#include "osm-gps-map.h" +#include "utility_tools.h" #define UI_fILE "./utility_tools.ui" + + +// void change_image(OsmGpsMap *map, float lat, float lon, OsmGpsMapImage *image) +// { +// if (g_last_image) +// osm_gps_map_image_remove(map, g_last_image); +// osm_gps_map_image_add(map, lat, lon, image); +// } + + void utility_tools(GtkButton *but, gpointer udata) { GtkBuilder *builder; @@ -13,16 +23,24 @@ void utility_tools(GtkButton *but, gpointer udata) g_warning("%s", error->message); g_free(error); } - GtkWidget *window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window")); + window = GTK_WIDGET(gtk_builder_get_object(builder, "util_window")); GtkContainer *map_container = GTK_CONTAINER(gtk_builder_get_object(builder, "map_layout")); - OsmGpsMap *map = g_object_new (OSM_TYPE_GPS_MAP, - "map-source", OSM_GPS_MAP_SOURCE_OPENSTREETMAP, + + + util_map = g_object_new (OSM_TYPE_GPS_MAP, + "map-source", OSM_GPS_MAP_SOURCE_GOOGLE_HYBRID, "tile-cache", "/tmp/", NULL); - gtk_widget_set_size_request(GTK_WIDGET(map), 800, 600); + osm_gps_map_set_center_and_zoom (util_map, 15.4589, 75.0078, 10); + g_red_image = gdk_pixbuf_new_from_file_at_size ("red.png", 24,24,NULL); + g_green_image = gdk_pixbuf_new_from_file_at_size ("green.png", 24,24,NULL); - gtk_container_add(map_container, GTK_WIDGET(map)); + // 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(util_map,15.518597, 74.925584, g_green_image); + gtk_widget_set_size_request(GTK_WIDGET(util_map), 600, 500); + + gtk_container_add(map_container, GTK_WIDGET(util_map)); gtk_widget_show_all(window); gtk_main(); diff --git a/iPDC/utility_tools.h b/iPDC/utility_tools.h index d583201..01dd4d1 100644 --- a/iPDC/utility_tools.h +++ b/iPDC/utility_tools.h @@ -1,4 +1,5 @@ #include +#include "osm-gps-map.h" /* Convenience macros for obtaining objects from UI file */ #define CH_GET_OBJECT(builder, name, type, data) \ @@ -6,4 +7,10 @@ #define CH_GET_WIDGET(builder, name, data) \ CH_GET_OBJECT(builder, name, GTK_WIDGET, data) +OsmGpsMap *util_map; +GtkWidget *window; +static GdkPixbuf *g_red_image = NULL; +static GdkPixbuf *g_green_image = NULL; +static OsmGpsMapImage *g_last_image = NULL; + void utility_tools(GtkButton *but, gpointer udata); \ No newline at end of file diff --git a/resources/align_sort.c b/resources/align_sort.c new file mode 100644 index 0000000..3465760 --- /dev/null +++ b/resources/align_sort.c @@ -0,0 +1,1662 @@ +/* ----------------------------------------------------------------------------- + * align_sort.c + * + * iPDC - Phasor Data Concentrator + * + * Copyright (C) 2011-2012 Nitesh Pandit + * Copyright (C) 2011-2012 Kedar V. Khandeparkar + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: + * Nitesh Pandit + * Kedar V. Khandeparkar + * + * ----------------------------------------------------------------------------- */ + + +#include +#include +#include +#include +#include "parser.h" +#include "global.h" +#include "align_sort.h" +#include "connections.h" +#include "dallocate.h" + +/* ------------------------------------------------------------------------------------ */ +/* Functions in align_sort.c */ +/* ------------------------------------------------------------------------------------ */ + +/* 1. void time_align(struct data_frame *df) */ +/* 2. void assign_df_to_TSB(struct data_frame *df,int index) */ +/* 3. void dispatch(int index) */ +/* 4. void sort_data_inside_TSB(int index) */ +/* 5. void clear_TSB(int index) */ +/* 6. void create_dataframe(int index) */ +/* 7. void create_cfgframe() */ + +/* -----------------------------------------------------------------------------*/ + + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION time_align(): */ +/* It searches for the correct TSB[index] where data frame df is to be */ +/* assigned. If the df has soc and fracsec which is older then soc and fracsec */ +/* of TSB[first] then we discard the data frame */ +/* ---------------------------------------------------------------------------- */ + +void time_align(struct data_frame *df) { + + int flag = 0; + int i; + unsigned int IDcode; + unsigned int df_soc,df_fracsec,tsb_soc,tsb_fracsec; + + if (front == -1) { // TSB is used for the first time + + front = rear = 0; + assign_df_to_TSB(df,front); + + struct cfg_frame *temp_cfg = cfgfirst; + while(temp_cfg != NULL) { + + printf("%d--",to_intconvertor(temp_cfg->idcode)); + temp_cfg = temp_cfg->cfgnext; + } + printf("\n"); + return; + + } else { + + df_soc = to_long_int_convertor(df->soc); + unsigned char *fsec; + fsec = malloc(3*sizeof(unsigned char)); + fsec[0] = df->fracsec[1]; + fsec[1] = df->fracsec[2]; + fsec[2] = df->fracsec[3]; + df_fracsec = to_long_int_convertor1(fsec); + + unsigned char *tsb_fsec; + tsb_fsec = malloc(3*sizeof(unsigned char)); + tsb_fsec[0] = TSB[front].fracsec[1]; + tsb_fsec[1] = TSB[front].fracsec[2]; + tsb_fsec[2] = TSB[front].fracsec[3]; + + tsb_soc = to_long_int_convertor((unsigned char *)TSB[front].soc); + + tsb_fracsec = to_long_int_convertor1(tsb_fsec); + IDcode = to_intconvertor(df->idcode); + + if((old_df_front != -1) && ((df_soc < ODFT[old_df_front].soc) || ((df_soc == ODFT[old_df_front].soc) && (df_fracsec < ODFT[old_df_front].fracsec)))) { +// if((df_soc < tsb_soc) || ((df_soc == tsb_soc) && (df_fracsec < tsb_fracsec))) { + + free_dataframe_object(df); + myfree(tsb_fsec); + myfree(fsec); + unsigned char *tsb_fsec1; + tsb_fsec1 = malloc(3*sizeof(unsigned char)); + tsb_fsec1[0] = TSB[rear].fracsec[1]; + tsb_fsec1[1] = TSB[rear].fracsec[2]; + tsb_fsec1[2] = TSB[rear].fracsec[3]; + unsigned int tsb_fracsec1 = to_long_int_convertor1(tsb_fsec1); + unsigned int tsb_soc1 = to_long_int_convertor((unsigned char *)TSB[rear].soc); + printf("LOssId = %u df soc %u fsec =%u front tsb_soc %u tsb_fsec %u rear soc %u fsec %u \n",IDcode,df_soc,df_fracsec,tsb_soc,tsb_fracsec,tsb_soc1,tsb_fracsec1); + writeTimeToLog(88,IDcode,df_soc,df_fracsec); + pthread_mutex_unlock(&mutex_on_thread); // Added by KK on 19-Oct-2013 + return; + } + + for(i = 0; isoc,4); + copy_cbyc((unsigned char *)TSB[index].fracsec,df->fracsec,4); + TSB[index].num = 0; + + // Kedar 06-05-2013 v1.4 initialize the old soc and fracsec + unsigned char *fsec; + fsec = malloc(3*sizeof(unsigned char)); + fsec[0] = TSB[index].fracsec[1]; + fsec[1] = TSB[index].fracsec[2]; + fsec[2] = TSB[index].fracsec[3]; + + if(old_df_front == -1) { + + old_df_front = 0; + old_df_rear = 0; + + ODFT[old_df_rear].soc = to_long_int_convertor(TSB[index].soc); + ODFT[old_df_rear].fracsec = to_long_int_convertor1(fsec); + + } else { + + old_df_rear = (old_df_rear + 1)%OLDFRAMECOUNT; + ODFT[old_df_rear].soc = to_long_int_convertor(TSB[index].soc); + ODFT[old_df_rear].fracsec = to_long_int_convertor1(fsec); + } + + Tsb_Count++; + TSB[index].first_data_frame = df; /* Assign df to the 'first_data_frame' in the data frame linked list of TSB[index] */ + TSB[index].count = 1; + /* Now we need to store the pmu/pdc id in the pmupdc_id_list that would be required while sorting */ + struct pmupdc_id_list *temp_pmuid; + while(temp_cfg != NULL) { + + /* Create a node of the type 'pmupdc_id_list' and copy the pmu/pde id from the cfg to it */ + struct pmupdc_id_list *pmuid = malloc(sizeof(struct pmupdc_id_list)); + pmuid->idcode = malloc(3); + memset(pmuid->idcode,'\0',3); + copy_cbyc((unsigned char *)pmuid->idcode,temp_cfg->idcode,2); + pmuid->num_pmu = to_intconvertor(temp_cfg->num_pmu); + pmuid->nextid = NULL; + TSB[index].num++; + + if(TSB[index].idlist == NULL) { /* Assign the pmuid to the idlist as it is the first id in the list */ + + TSB[index].idlist = temp_pmuid = pmuid; + + } else { + + temp_pmuid->nextid = pmuid; + temp_pmuid = pmuid; + + } + + temp_cfg = temp_cfg->cfgnext; + } // while ends . A pmu/pdc id list is created for the TSB[index] + + TSB[index].counter = 1; + + unsigned int IDcode = to_intconvertor(df->idcode); + unsigned int df_soc = to_long_int_convertor(df->soc); + fsec[0] = df->fracsec[1]; + fsec[1] = df->fracsec[2]; + fsec[2] = df->fracsec[3]; + unsigned int df_fracsec = to_long_int_convertor1(fsec); + + if(TSB[index].count == TSB[index].num) { + + int xx = index; + writeTimeToLog(2,IDcode,df_soc,df_fracsec); // Checkpoint time before sorting + intermediate_dispatch(xx); + } else { + + writeTimeToLog(2,IDcode,df_soc,df_fracsec); // Checkpoint time before sorting + } + + int k = 0; + for (k=0;kidcode); + df_soc = to_long_int_convertor(TSB[k].first_data_frame->soc); + fsec[0] = TSB[k].first_data_frame->fracsec[1]; + fsec[1] = TSB[k].first_data_frame->fracsec[2]; + fsec[2] = TSB[k].first_data_frame->fracsec[3]; + df_fracsec = to_long_int_convertor1(fsec); + writeTimeToLog(2,IDcode,df_soc,df_fracsec); // Checkpoint time before sorting + intermediate_dispatch(k); + } + } + } + free(fsec); + pthread_mutex_unlock(&mutex_on_thread); // Added by KK on 19-Oct-2013 + + } else { // 1 if else + + + struct cfg_frame *temp_cfg = cfgfirst; + if(TSB[index].first_data_frame == NULL) { // 2 if + + /* After TSB[index] is cleared this is the first data frame for it. + The memory for the member variables of TSB[index] has already + been allocated. Hence after dispatch() and clear_TSB() operation + this TSB is to be assigned the data_frame for the first time. */ + + copy_cbyc((unsigned char *)TSB[index].soc,df->soc,4); + copy_cbyc((unsigned char *)TSB[index].fracsec,df->fracsec,4); + + // Kedar 06-05-2013 v1.4 Reset the old frame times + old_df_rear = (old_df_rear + 1) % OLDFRAMECOUNT; + + ODFT[old_df_rear].soc = to_long_int_convertor(TSB[index].soc); + + unsigned char *fsec; + fsec = malloc(3*sizeof(unsigned char)); + fsec[0] = TSB[index].fracsec[1]; + fsec[1] = TSB[index].fracsec[2]; + fsec[2] = TSB[index].fracsec[3]; + ODFT[old_df_rear].fracsec = to_long_int_convertor1(fsec); + + TSB[index].first_data_frame = df; /* Assign df to the 'first_data_frame' in the data frame linked list of TSB[index] */ + Tsb_Count++; + TSB[index].count = 1; + TSB[index].num = 0; + /* Now we need to store the pmu/pdc id in the pmupdc_id_list + that would be required while sorting */ + struct pmupdc_id_list *temp_pmuid; + while(temp_cfg != NULL) { + + /* Create a node of the type 'pmupdc_id_list' and + copy the pmu/pde id from the cfg to it */ + + struct pmupdc_id_list *pmuid = malloc(sizeof(struct pmupdc_id_list)); + pmuid->idcode = malloc(3); + memset(pmuid->idcode,'\0',3); + copy_cbyc((unsigned char *)pmuid->idcode,temp_cfg->idcode,2); + pmuid->num_pmu = to_intconvertor(temp_cfg->num_pmu); + pmuid->nextid = NULL; + TSB[index].num++; + + if(TSB[index].idlist == NULL) { /* Assign the pmuid to the idlist as it is the first id in the list */ + + TSB[index].idlist = temp_pmuid = pmuid; + + } else { + + temp_pmuid->nextid = pmuid; + temp_pmuid = pmuid; + + } + + temp_cfg = temp_cfg->cfgnext; + } // while ends + + TSB[index].counter = 1; + + unsigned int IDcode = to_intconvertor(df->idcode); + unsigned int df_soc = to_long_int_convertor(df->soc); + fsec[0] = df->fracsec[1]; + fsec[1] = df->fracsec[2]; + fsec[2] = df->fracsec[3]; + unsigned int df_fracsec = to_long_int_convertor1(fsec); + + if(TSB[index].count == TSB[index].num) { + + int xx = index; + writeTimeToLog(2,IDcode,df_soc,df_fracsec); // Checkpoint time before sorting + intermediate_dispatch(xx); + } else { + + writeTimeToLog(2,IDcode,df_soc,df_fracsec); // Checkpoint time before sorting + } + + int k = 0; + for (k=0;kidcode); + df_soc = to_long_int_convertor(TSB[k].first_data_frame->soc); + fsec[0] = TSB[k].first_data_frame->fracsec[1]; + fsec[1] = TSB[k].first_data_frame->fracsec[2]; + fsec[2] = TSB[k].first_data_frame->fracsec[3]; + df_fracsec = to_long_int_convertor1(fsec); + writeTimeToLog(2,IDcode,df_soc,df_fracsec); // Checkpoint time before sorting + intermediate_dispatch(k); + } + } + } + + free(fsec); + pthread_mutex_unlock(&mutex_on_thread); // Added by KK on 19-Oct-2013 + + } else { // 2 if else + + // printf("Inside assign_df id = %d index %d front = %d,rear = %d\n",IDcode,index,front,rear); + + /* Traverse the data frames of TSB[index] and assign the df to 'dnext' of + the last element in the data frame LL.*/ + struct data_frame *temp_df,*check_df; + + /* Need to check if df with same idcode and soc is already assigned to + the TSB[index] */ + check_df = TSB[index].first_data_frame; + while(check_df != NULL) { + + if(!ncmp_cbyc(check_df->idcode,df->idcode,2)) { + + free_dataframe_object(df); + return; + + } else { + + check_df = check_df->dnext; + + } + } + + temp_df = TSB[index].first_data_frame; + while(temp_df->dnext != NULL) { + + temp_df = temp_df->dnext; + + } + + temp_df->dnext = df; + TSB[index].count++; + + // New Code by Kedar + unsigned int df_soc,df_fracsec; + df_soc = to_long_int_convertor(df->soc); + unsigned char *fsec; + fsec = malloc(3*sizeof(unsigned char)); + fsec[0] = df->fracsec[1]; + fsec[1] = df->fracsec[2]; + fsec[2] = df->fracsec[3]; + df_fracsec = to_long_int_convertor1(fsec); + unsigned int IDcode = to_intconvertor(df->idcode); + free(fsec); + writeTimeToLog(2,IDcode,df_soc,df_fracsec); + pthread_mutex_unlock(&mutex_on_thread); // Added by KK on 19-Oct-2013 + + if(TSB[index].count == TSB[index].num) { + + int xx = index; + intermediate_dispatch(xx); + } + } // 2 if ends + + } // 1 if ends +} + +void intermediate_dispatch(int xx) { + + unsigned int yy = xx; + + if(front < rear) { + + if(xx == rear) { + + dispatch(xx); + rear= (rear - 1 )<0 ? rear-1+MAXTSB:rear -1; // one step backward + } else if(xx == front) { + + dispatch(front); + front = (front + 1) % MAXTSB; + + } else if(xx rear) { + + if(xx == rear) { + + dispatch(rear); + + if(front - rear == MAXTSB) + { + rear = front; + } else { + + rear = rear - 1; + if(rear <0) + rear = rear + MAXTSB; + } + + } else if(xx == front) { + + dispatch(front); + front = (front + 1) % MAXTSB; + + } else if(xx > front) { // xx>front + + dispatch(xx); + int rr = xx; + + while (rr != rear) { + + int h = (rr + 1) % MAXTSB; + + copy_cbyc (TSB[rr].soc,(unsigned char *)TSB[h].soc,4); + copy_cbyc (TSB[rr].fracsec,(unsigned char *)TSB[h].fracsec,4); + + TSB[rr].count = TSB[h].count; + TSB[rr].num = TSB[h].num; + TSB[rr].counter = TSB[h].counter; + TSB[rr].idlist = TSB[h].idlist; + TSB[rr].first_data_frame = TSB[h].first_data_frame; + rr = (rr + 1) % MAXTSB; + } + + memset(TSB[rear].soc,'\0',5); + memset(TSB[rear].fracsec,'\0',5); + TSB[rear].count = 0; + TSB[rear].num = 0; + TSB[rear].counter = 0; + TSB[rear].first_data_frame = NULL; + TSB[rear].idlist = NULL; + rear= (rear - 1 )<0 ? rear-1+MAXTSB:rear -1; // one step backward + + } else if(xx < front) { + + dispatch(xx); + int rr = xx; + while (rr != rear) { + + int h = (rr + 1) % MAXTSB; + + copy_cbyc (TSB[rr].soc,(unsigned char *)TSB[h].soc,4); + copy_cbyc (TSB[rr].fracsec,(unsigned char *)TSB[h].fracsec,4); + + TSB[rr].count = TSB[h].count; + TSB[rr].num = TSB[h].num; + TSB[rr].counter = TSB[h].counter; + TSB[rr].idlist = TSB[h].idlist; + TSB[rr].first_data_frame = TSB[h].first_data_frame; + rr = (rr + 1) % MAXTSB; + } + + memset(TSB[rear].soc,'\0',5); + memset(TSB[rear].fracsec,'\0',5); + TSB[rear].count = 0; + TSB[rear].num = 0; + TSB[rear].counter = 0; + TSB[rear].first_data_frame = NULL; + TSB[rear].idlist = NULL; + rear= (rear - 1 )<0 ? rear-1+MAXTSB:rear -1; // one step backward + } + } else { + + dispatch(front); + } +} + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION dispatch(): */ +/* It dispatches the combined data frame to all the destination devices */ +/* ---------------------------------------------------------------------------- */ + +void dispatch(int index) { + + int size,flag = 0; + Tsb_Count--; + unsigned int tsb_soc = to_long_int_convertor(TSB[index].soc); + struct data_frame *df = TSB[index].first_data_frame; + unsigned int IDcode = to_intconvertor(df->idcode); + adjustOldFrameCount(index); + + unsigned char *tsb_fsec; + tsb_fsec = malloc(3*sizeof(unsigned char)); + tsb_fsec[0] = TSB[index].fracsec[1]; + tsb_fsec[1] = TSB[index].fracsec[2]; + tsb_fsec[2] = TSB[index].fracsec[3]; + unsigned int tsb_fracsec = to_long_int_convertor1(tsb_fsec); + +// writeTimeToLog(3,IDcode,tsb_soc,tsb_fracsec); // Checkpoint time before sorting + + create_dataframe(index); + + writeTimeToLog(3,IDcode,tsb_soc,tsb_fracsec); // Checkpoint time after Creation of combined data frame + + pthread_mutex_lock(&mutex_Upper_Layer_Details); + struct Upper_Layer_Details *temp_pdc = ULfirst; + + while(temp_pdc != NULL ) { + + if((temp_pdc->UL_upper_pdc_cfgsent == 1) && (temp_pdc->UL_data_transmission_off == 0)) { + + if(flag == 0) { + + size = create_dataframe(index); +// writeTimeToLog(2,IDcode,tsb_soc,tsb_fracsec); //Checkpoint time after creation of combined data frame + flag = 1; + } + + if(temp_pdc->config_change == 1) { + + dataframe[14] = 0x04; + dataframe[15] = 0x00; + + } else { + + dataframe[14] = 0x00; + dataframe[15] = 0x00; + + } + + if(temp_pdc->port == UDPPORT) { + + if (sendto(temp_pdc->sockfd,dataframe, size, 0, + (struct sockaddr *)&temp_pdc->pdc_addr,sizeof(temp_pdc->pdc_addr)) == -1) + perror("sendto"); + + } else if((temp_pdc->port == TCPPORT) && (temp_pdc->tcpup == 1)) { + + if(send(temp_pdc->sockfd,dataframe,size, 0)== -1) { + perror("send"); + //printf("TCP connection closed\n"); + temp_pdc->tcpup = 0; + pthread_cancel(temp_pdc->thread_id); + } + } + } + temp_pdc = temp_pdc->next; + } + pthread_mutex_unlock(&mutex_Upper_Layer_Details); + free(tsb_fsec); + /*if(dataframe != NULL) + free(dataframe);*/ + clear_TSB(index); +} + + +void adjustOldFrameCount(int index) { + + int flag = 0; + int i; + + unsigned char *tsb_fsec; + unsigned int tsb_soc,tsb_fracsec; + + tsb_fsec = malloc(3*sizeof(unsigned char)); + tsb_fsec[0] = TSB[index].fracsec[1]; + tsb_fsec[1] = TSB[index].fracsec[2]; + tsb_fsec[2] = TSB[index].fracsec[3]; + + tsb_soc = to_long_int_convertor((unsigned char *)TSB[index].soc); + tsb_fracsec = to_long_int_convertor1(tsb_fsec); + + for(i = 0; i< OLDFRAMECOUNT; i++) { + + if((ODFT[i].soc == tsb_soc) && (ODFT[i].fracsec == tsb_fracsec)) { + + flag = 1; + break; + } + } + + if(flag) + { + int xx = i; + ODFT[xx].soc = 0; + ODFT[xx].fracsec = 0; + if(old_df_front < old_df_rear) { + + if(xx == old_df_rear) { + + old_df_rear= (old_df_rear - 1)%OLDFRAMECOUNT; + if(old_df_rear <0) + + old_df_rear = old_df_rear + OLDFRAMECOUNT;// + + } else if(xx == old_df_front) { + + old_df_front = (old_df_front + 1) % OLDFRAMECOUNT; + + } else if(xx < old_df_rear) { + + while (xx < old_df_rear) { + + ODFT[xx].soc = ODFT[xx + 1].soc; + ODFT[xx].fracsec = ODFT[xx + 1].fracsec; + xx++; + } + + ODFT[old_df_rear].soc = 0; + ODFT[old_df_rear].fracsec = 0; + + old_df_rear = (old_df_rear - 1) % OLDFRAMECOUNT; + if(old_df_rear < 0) + old_df_rear = old_df_rear + OLDFRAMECOUNT; + } + } else if (old_df_front > old_df_rear) { + + if(xx == old_df_rear) { + + if(old_df_front - old_df_rear == OLDFRAMECOUNT) + { + //front = rear; + old_df_rear = old_df_front; + + } else { + + old_df_rear = old_df_rear - 1; + if(old_df_rear <0) + old_df_rear = old_df_rear + OLDFRAMECOUNT; + } + + } else if(xx == old_df_front) { + + old_df_front = (old_df_front + 1) % OLDFRAMECOUNT; + + } else { // xx>front + + int rr = xx; + while (rr != old_df_rear) { + + int h = (rr + 1) % OLDFRAMECOUNT; + ODFT[rr].soc = ODFT[h].soc; + ODFT[rr].fracsec = ODFT[h].fracsec; + rr = (rr + 1) % OLDFRAMECOUNT; + } + + old_df_rear = (old_df_rear - 1) % OLDFRAMECOUNT; + if(old_df_rear < 0) + old_df_rear = old_df_rear + OLDFRAMECOUNT; + } + + } else { + + old_df_front = (old_df_front + 1)%OLDFRAMECOUNT; + old_df_rear = old_df_front; + } + }else { + + // printf("No match with ODFT\n"); + } +} + + + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION clear_TSB(): */ +/* It clears TSB[index] and frees all data frame objects after the data frames */ +/* in TSB[index] have been dispatched to destination device */ +/* ---------------------------------------------------------------------------- */ + +void clear_TSB(int index) { // + + memset(TSB[index].soc,'\0',5); + memset(TSB[index].fracsec,'\0',5); + + struct pmupdc_id_list *t_list,*r_list; + t_list = TSB[index].idlist; + TSB[index].count = 0; + + while(t_list != NULL) { + + r_list = t_list->nextid; + free(t_list->idcode); + free(t_list); + t_list = r_list; + } + + struct data_frame *t,*r; + t = TSB[index].first_data_frame; + + while(t != NULL) { + + r = t->dnext; + free_dataframe_object(t); + t = r; + } + + TSB[index].first_data_frame = NULL; + TSB[index].idlist = NULL; + TSB[index].num = 0; + TSB[index].counter = 0; +} + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION create_dataframe(): */ +/* It creates the IEEEC37.118 Standard based combined data frame from the data */ +/* frames received from all the source devices to be sent to the destination */ +/* devices. */ +/* ---------------------------------------------------------------------------- */ +int create_dataframe(int index) { + + int total_frame_size = 0; + unsigned char temp[3]; + struct data_frame *temp_df; + uint16_t chk; + unsigned int offset = 14; + //unsigned int dfSize; + + temp_df = TSB[index].first_data_frame; + + // Calculate the single combined data frame size + total_frame_size = COMBINE_DF_SIZE + 16; /* 16 is for comman fields SYNC + FRAMESIZE + idcode + soc + fracsec + checksum */ + + if(dataframe == NULL) { + + dataframe = malloc((total_frame_size + 1)*sizeof(unsigned char)); + if(!dataframe) + printf("No enough memory for dataframe\n"); + memset(dataframe,'\0',total_frame_size+1); + + } else { + + char *fsize; + fsize = malloc(3); + fsize[0] = dataframe[2]; + fsize[1] = dataframe[3]; + fsize[2] = '\0'; + int size = to_intconvertor(fsize); + free(fsize); + + if(size idcode)); + + if((found_item = hsearch(item, FIND)) == NULL) { + printf("Node not found in hash table\n"); + break; + } + + z = offset + ((struct hashTable *)found_item->data)->startIndex; + ((struct hashTable *)found_item->data)->visited = true; + attacheEachDataFrame(temp_df,z); + temp_df = temp_df->dnext; + } // 1 while + + // Search for unvisted nodes/Missing frames + sprintf(item.key,"%d",to_long_int_convertor1(cfgfirst->idcode)); + if((found_item = hsearch(item, FIND)) != NULL) { + + checkForMissingFrames(found_item); + + } else { + printf("no item of this kind in the has table\n"); + } + + // Attach a checksum + int totalSize = offset + COMBINE_DF_SIZE; + chk = compute_CRC(dataframe,totalSize); + dataframe[totalSize++] = (chk >> 8) & ~(~0<<8); /* CHKSUM high byte; */ + dataframe[totalSize++] = (chk ) & ~(~0<<8); /* CHKSUM low byte; */ + + // For iPDC configuration changed + old_fsize = totalSize; + + return totalSize; +} + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION create_cfgframe(): */ +/* It creates the IEEEC37.118 Standard based combined configuration frame from */ +/* the configuration frames received from all the source devices to be sent to */ +/* destination devices */ +/* ---------------------------------------------------------------------------- */ + +int create_cfgframe() { + + struct cfg_frame *temp_cfg; + int total_frame_size = 0,count = 0; + unsigned char datarate[2],soc[4],fracsec[4]; // hard coded + int total_num_pmu = 0; + unsigned char time_base[4]; + unsigned int fsize,num_pmu,phnmr,dgnmr,annmr; + unsigned int data_rate,temp_data_rate; + unsigned long int sec,frac = 0,temp_tb,tb; + uint16_t chk; + + sec = (long int)time (NULL); + long_int_to_ascii_convertor(sec,soc); + long_int_to_ascii_convertor(frac,fracsec); + + temp_cfg = cfgfirst; + + while(temp_cfg != NULL) { + + if(count == 0) { // Copy the soc,fracsec,timebase from the first CFG to the combined CFG + + //SEPARATE TIMBASE + tb = to_long_int_convertor(temp_cfg->time_base); + copy_cbyc (time_base,temp_cfg->time_base,4); + + data_rate = to_intconvertor(temp_cfg->data_rate); + copy_cbyc (datarate,temp_cfg->data_rate,2); + + fsize = to_intconvertor(temp_cfg->framesize); + total_frame_size += fsize; + count++; // count used to count num of cfg + + num_pmu = to_intconvertor(temp_cfg->num_pmu); + total_num_pmu += num_pmu; + temp_cfg = temp_cfg->cfgnext; + + } else { + + fsize = to_intconvertor(temp_cfg->framesize); + total_frame_size += fsize; + total_frame_size -= 24; + + // take the Lowest Timebase + temp_tb = to_long_int_convertor(temp_cfg->time_base); + if(temp_tb < tb) { + + copy_cbyc (time_base,temp_cfg->time_base,4); + tb = temp_tb; + + } + + // take the highest data rate + temp_data_rate = to_intconvertor(temp_cfg->data_rate); + if(temp_data_rate > data_rate) { + + copy_cbyc (datarate,temp_cfg->data_rate,2); + data_rate = temp_data_rate; + } + count++; // count used to count num of cfg + + num_pmu = to_intconvertor(temp_cfg->num_pmu); + total_num_pmu += num_pmu; + temp_cfg = temp_cfg->cfgnext; + } + + } // While ENDS + + cfgframe = malloc((total_frame_size + 1)*sizeof(unsigned char)); // Allocate memory for data frame + cfgframe[total_frame_size] = '\0'; + + // Start the Combined CFG frame creation + int z = 0; + byte_by_byte_copy(cfgframe,CFGSYNC,z,2); // SYNC + z += 2; + + unsigned char temp[3]; + memset(temp,'\0',3); + int_to_ascii_convertor(total_frame_size,temp); + byte_by_byte_copy(cfgframe,temp,z,2); // FRAME SIZE + z += 2; + + unsigned char tmp[2]; + tmp[0]= cfgframe[2]; + tmp[1]= cfgframe[3]; + int newl; + newl = to_intconvertor(tmp); + printf("CFG Frame Len %d.\n",newl); + + memset(temp,'\0',3); + int_to_ascii_convertor(PDC_IDCODE,temp); + byte_by_byte_copy(cfgframe,temp,z,2); // PDC ID + z += 2; + + byte_by_byte_copy(cfgframe,soc,z,4); //SOC + z += 4; + byte_by_byte_copy(cfgframe,fracsec,z,4); //FRACSEC + z += 4; + byte_by_byte_copy(cfgframe,time_base,z,4); //TIMEBASE + z += 4; + + memset(temp,'\0',3); + int_to_ascii_convertor(total_num_pmu,temp); + byte_by_byte_copy(cfgframe,temp,z,2); // No of PMU + z += 2; + + int i,j; + temp_cfg = cfgfirst; + + while(temp_cfg != NULL) { // 1 + + num_pmu = to_intconvertor(temp_cfg->num_pmu); + j = 0; + + while (j < num_pmu) { //2 + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->stn,z,16); // STN + z += 16; + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->idcode,z,2); // IDCODE + z += 2; + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->data_format,z,2); // FORMAT + z += 2; + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->phnmr,z,2); // PHNMR + z += 2; + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->annmr,z,2); // ANNMR + z += 2; + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->dgnmr,z,2); // DGNMR + z += 2; + + phnmr = to_intconvertor(temp_cfg->pmu[j]->phnmr); + annmr = to_intconvertor(temp_cfg->pmu[j]->annmr); + dgnmr = to_intconvertor(temp_cfg->pmu[j]->dgnmr); + + // Copy Phasor Names + if(phnmr != 0){ + + for(i = 0; ipmu[j]->cnext->phnames[i],z,16); // Phasor Names + z += 16; + } + } + + // Copy Analog Names + if(annmr != 0){ + + for(i = 0; ipmu[j]->cnext->angnames[i],z,16); // Analog Names + z += 16; + } + } + + // Copy Digital Names + if(dgnmr != 0) { + + struct dgnames *temp_dgname = temp_cfg->pmu[j]->cnext->first; + while (temp_dgname != NULL) { + + for(i = 0;i<16;i++) { + + byte_by_byte_copy(cfgframe,temp_dgname->dgn[i],z,16); // Digital Names + z += 16; + + } // Copy 16 channel names of digital word + + temp_dgname = temp_dgname->dg_next; + } // Go to next Digital word + + } + + // PHUNIT + if(phnmr != 0){ + + for (i = 0; ipmu[j]->phunit[i],z,4); // PHUNIT + z += 4; + } + } + + // ANUNIT + if(annmr != 0){ + + for (i = 0; ipmu[j]->anunit[i],z,4); // ANUNIT + z += 4; + + } + } + + // DGUNIT + if(dgnmr != 0){ + + for (i = 0; ipmu[j]->dgunit[i],z,4); // DGUNIT + z += 4; + } + + } + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->fnom,z,2); // FNOM + z += 2; + + byte_by_byte_copy(cfgframe,temp_cfg->pmu[j]->cfg_cnt,z,2); // CFGCNT + z += 2; + + j++; // index for pmu_num + + } // while 2 + + temp_cfg = temp_cfg->cfgnext; // Take next CFG + + } // while 1 + + + byte_by_byte_copy(cfgframe,datarate,z,2); // DATA RATE + z += 2; + + chk = compute_CRC(cfgframe,z); + cfgframe[z++] = (chk >> 8) & ~(~0<<8); /* CHKSUM high byte; */ + cfgframe[z++] = (chk ) & ~(~0<<8); /* CHKSUM low byte; */ + return z; +} + + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION unsigned char* generate_dummy_dataframe(int id): */ +/* ---------------------------------------------------------------------------- */ + +struct data_frame* generate_dummy_dataframe(unsigned char *idcode) +{ + int match=0,i,j=0, fsize=0; + unsigned char tempI[2]; + unsigned int num_pmu,phnmr,annmr,dgnmr; + struct cfg_frame *temp_cfg; + struct data_frame *df; + + unsigned char temp2[2] = {0, 0}; + unsigned char temp4[4] = {0, 0, 0, 0}; + unsigned char temp8[8] = {0, 0, 0, 0, 0, 0, 0, 0}; + + //printf("Inside generate_dummy_dataframe\n"); + + pthread_mutex_lock(&mutex_cfg); + + temp_cfg = cfgfirst; + + // Check for the data frame IDCODE in Configuration Frame? + while(temp_cfg != NULL){ + + if(!ncmp_cbyc((unsigned char *) idcode,temp_cfg->idcode,2)) { + + match = 1; + break; + + } else { + + temp_cfg = temp_cfg->cfgnext; + } + } + pthread_mutex_unlock(&mutex_cfg); + + // If idcode matches with cfg idcode + if(match){ + + //Allocate memory for data frame + df = malloc(sizeof(struct data_frame)); + if(!df) { + + printf("Not enough memory for dummy df\n"); + exit(1); + } + df->dnext = NULL; + + // Allocate memory for df->framesize + df->framesize = malloc(3*sizeof(unsigned char)); + if(!df->framesize) { + + printf("Not enough memory df->idcode\n"); + exit(1); + } + + // Allocate memory for df->idcode + df->idcode = malloc(3*sizeof(unsigned char)); + if(!df->idcode) { + + printf("Not enough memory df->idcode\n"); + exit(1); + } + + // Allocate memory for df->soc + df->soc = malloc(5*sizeof(unsigned char)); + if(!df->soc) { + + printf("Not enough memory df->soc\n"); + exit(1); + } + + // Allocate memory for df->fracsec + df->fracsec = malloc(5*sizeof(unsigned char)); + if(!df->fracsec) { + + printf("Not enough memory df->fracsec\n"); + exit(1); + } + + // Allocate Memeory For Each PMU + num_pmu = to_intconvertor(temp_cfg->num_pmu); + + /* For each PMU data */ + df->dpmu = malloc(num_pmu* sizeof(struct data_for_each_pmu *)); + + if(!df->dpmu) { + + printf("Not enough memory df->dpmu[][]\n"); + exit(1); + } + + for (i = 0; i < num_pmu; i++) { + + df->dpmu[i] = malloc(sizeof(struct data_for_each_pmu)); + } + + /* Now start separating the data from data frame */ + /* Copy Framesize */ + copy_cbyc (df->framesize,temp2,2); + df->framesize[2] = '\0'; + + //Copy IDCODE + copy_cbyc (df->idcode,idcode,2); + df->idcode[2] = '\0'; + + //Copy SOC + copy_cbyc (df->soc,temp4,4); + df->soc[4] = '\0'; + + //Copy FRACSEC + copy_cbyc (df->fracsec,temp4,4); + df->fracsec[4] = '\0'; + fsize += 16; // For SYNC + FRAMESIZE + idcode + soc + fracsec + checksum + + //Copy NUM PMU + df->num_pmu = num_pmu; + + // Separate the data for each PMU + while(jpmu[j]->phnmr); + annmr = to_intconvertor(temp_cfg->pmu[j]->annmr); + dgnmr = to_intconvertor(temp_cfg->pmu[j]->dgnmr); + + //Allocate memory for stat, Phasors, Analogs,Digitals and Phasors and Frequencies + /* Memory Allocation Begins */ + + // Allocate memory for stat + df->dpmu[j]->stat = malloc(3*sizeof(unsigned char)); + + if(!df->dpmu[j]->stat) { + + printf("Not enough memory for df->dpmu[j]->stat\n"); + } + + // Allocate memory for Phasor + df->dpmu[j]->phasors = malloc(phnmr*sizeof(unsigned char *)); + + if(!df->dpmu[j]->phasors) { + + printf("Not enough memory df->dpmu[j]->phasors[][]\n"); + exit(1); + } + + if(temp_cfg->pmu[j]->fmt->phasor == '1') { + + for (i = 0; i < phnmr; i++) + + df->dpmu[j]->phasors[i] = malloc(9*sizeof(unsigned char)); + } else { + + for (i = 0; i < phnmr; i++) + + df->dpmu[j]->phasors[i] = malloc(5*sizeof(unsigned char)); + } + + /* Allocate memory for Analogs */ + df->dpmu[j]->analog = malloc(annmr*sizeof(unsigned char *)); + + if(!df->dpmu[j]->analog) { + + printf("Not enough memory df->dpmu[j]->analog[][]\n"); + exit(1); + } + + if(temp_cfg->pmu[j]->fmt->analog == '1') { + + for (i = 0; i < annmr; i++) + + df->dpmu[j]->analog[i] = malloc(9*sizeof(unsigned char)); + } else { + + for (i = 0; i < annmr; i++) + + df->dpmu[j]->analog[i] = malloc(5*sizeof(unsigned char)); + } + + /* Allocate memory for Frequency & DFREQ */ + if(temp_cfg->pmu[j]->fmt->freq == '1') { + + df->dpmu[j]->freq = malloc(5*sizeof(unsigned char)); + df->dpmu[j]->dfreq = malloc(5*sizeof(unsigned char)); + + } else { + + df->dpmu[j]->freq = malloc(3*sizeof(unsigned char)); + df->dpmu[j]->dfreq = malloc(3*sizeof(unsigned char)); + } + + /* Allocate memory for Digital */ + df->dpmu[j]->digital = malloc(dgnmr* sizeof(unsigned char*)); + + if(!df->dpmu[j]->digital) { + + printf("Not enough memory df->dpmu[j]->digital[][]\n"); + exit(1); + } + + for (i = 0; i < dgnmr; i++) { + + df->dpmu[j]->digital[i] = malloc(3*sizeof(unsigned char)); + } + /* Memory Allocation Ends here */ + + // Copy the PMU data fields + tempI[0] = 0x82; //changed by Kedar on 4-7-2013 + tempI[1] = 0x00; + copy_cbyc (df->dpmu[j]->stat,tempI,2); + df->dpmu[j]->stat[2] = '\0'; + fsize += 2; + + // Copy Format Word + df->dpmu[j]->fmt = malloc(sizeof(struct format)); + df->dpmu[j]->fmt->freq = temp_cfg->pmu[j]->fmt->freq; + df->dpmu[j]->fmt->analog = temp_cfg->pmu[j]->fmt->analog; + df->dpmu[j]->fmt->phasor = temp_cfg->pmu[j]->fmt->phasor; + df->dpmu[j]->fmt->polar = temp_cfg->pmu[j]->fmt->polar; + + // Copy number of phasors, analogs, and digitals + df->dpmu[j]->phnmr = phnmr; + df->dpmu[j]->annmr = annmr; + df->dpmu[j]->dgnmr = dgnmr; + + //Phasors + if(temp_cfg->pmu[j]->fmt->phasor == '1') { + + for(i=0;idpmu[j]->phasors[i],temp8,8); + df->dpmu[j]->phasors[i][8] = '\0'; + fsize += 8; + } + } else { + + for(i=0;idpmu[j]->phasors[i],temp4,4); + df->dpmu[j]->phasors[i][4] = '\0'; + fsize += 4; + } + } + + /* For Freq */ + if(temp_cfg->pmu[j]->fmt->freq == '1') { + + copy_cbyc (df->dpmu[j]->freq,temp4,4); + df->dpmu[j]->freq[4] = '\0'; + fsize += 4; + + copy_cbyc (df->dpmu[j]->dfreq,temp4,4); + df->dpmu[j]->dfreq[4] = '\0'; + fsize += 4; + + } else { + + copy_cbyc (df->dpmu[j]->freq,temp2,2); + df->dpmu[j]->freq[2] = '\0'; + fsize += 2; + + copy_cbyc (df->dpmu[j]->dfreq,temp2,2); + df->dpmu[j]->dfreq[2] = '\0'; + fsize += 2; + } + + /* For Analogs */ + if(temp_cfg->pmu[j]->fmt->analog == '1') { + + for(i = 0; idpmu[j]->analog[i],temp4,4); + df->dpmu[j]->analog[i][4] = '\0'; + fsize += 4; + } + } else { + for(i = 0; idpmu[j]->analog[i],temp2,2); + df->dpmu[j]->analog[i][2] = '\0'; + fsize += 2; + } + } + + /* For Digital */ + for(i = 0; idpmu[j]->digital[i],temp2,2); + df->dpmu[j]->digital[i][2] = '\0'; + fsize += 2; + } + + j++; + } //While ends for sub PMUs + + tempI[0] = fsize>>8; + tempI[1] = fsize; + copy_cbyc (df->framesize,tempI,2); + df->framesize[2] = '\0'; + + return df; + } +} + +/* ---------------------------------------------------------------------------- */ +/* int matchDataFrameTimeToTSBTime(unsigned int df_soc,unsigned int df_fracsec) */ +/* ---------------------------------------------------------------------------- */ + +int matchDataFrameTimeToTSBTime(unsigned int df_soc,unsigned int df_fracsec) { + + pthread_mutex_lock(&mutex_on_TSB); + + int flag = 0,i; + unsigned int tsb_soc,tsb_fracsec; + unsigned char *tsb_fsec; + tsb_fsec = malloc(3*sizeof(unsigned char)); + + for(i = 0; idata)->visited == true) { + + ((struct hashTable *)found_item->data)->visited = false; + int nextid = ((struct hashTable *)found_item->data)->nextIdcode; + if( nextid != -1) { + + sprintf(item.key,"%d",nextid); + + if((found_item = hsearch(item, FIND)) == NULL) { + + printf("Node not found in hash table--\n"); + return; + } + + checkForMissingFrames(found_item); + } + + } else if (((struct hashTable *)found_item->data)->visited == false) { + + unsigned char *temp = malloc(3*sizeof(unsigned char)); + memset(temp,'\0',3); + int_to_ascii_convertor(((struct hashTable *)found_item->data)->Idcode,temp); + + struct data_frame *curr_df; + curr_df = generate_dummy_dataframe(temp); + free(temp); + + int z = ((struct hashTable *)found_item->data)->startIndex; + attacheEachDataFrame(curr_df,z); + + int nextid = ((struct hashTable *)found_item->data)->nextIdcode; + if( nextid != -1) { + sprintf(item.key,"%d",nextid); + if((found_item = hsearch(item, FIND)) == NULL) { + + printf("Node not found in hash table++\n"); + return; + } + + checkForMissingFrames(found_item); + } + } +} + +/* ---------------------------------------------------------------------------- */ +/* void attacheEachDataFrame(struct data_frame *temp_df,int z) */ +/* ---------------------------------------------------------------------------- */ + +void attacheEachDataFrame(struct data_frame *temp_df,int z) { + + int j = 0; + + while(j < temp_df->num_pmu) { // 2 + + //Copy STAT Word + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->stat,z,2); + z += 2; + + int i = 0; + //Copy Phasors + if(temp_df->dpmu[j]->phnmr != 0) { + + if(temp_df->dpmu[j]->fmt->phasor == '1') { + + while(i < temp_df->dpmu[j]->phnmr) { + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->phasors[i],z,8); // Phasors + z += 8; + i++; + } + + } else { + + while(i < temp_df->dpmu[j]->phnmr) { + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->phasors[i],z,4); // Phasors + z += 4; + i++; + } + } + } + + //Copy FREQ + if(temp_df->dpmu[j]->fmt->freq == '1') { + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->freq,z,4); // FREQ + z += 4; + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->dfreq,z,4); // FREQ + z += 4; + + } else { + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->freq,z,2); // FREQ + z += 2; + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->dfreq,z,2); // FREQ + z += 2; + + } + + // Copy Analogs + if(temp_df->dpmu[j]->annmr != 0) { + + if(temp_df->dpmu[j]->fmt->analog == '1') { + + for(i = 0; idpmu[j]->annmr; i++){ + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->analog[i],z,4); // ANALOGS + z += 4; + } + + } else { + + for(i = 0; idpmu[j]->annmr; i++){ + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->analog[i],z,2); // ANALOGS + z += 2; + } + } + } + + i = 0; + + //Copy DIGITAL + if(temp_df->dpmu[j]->dgnmr != 0) { + + while(i < temp_df->dpmu[j]->dgnmr) { + + byte_by_byte_copy(dataframe,temp_df->dpmu[j]->digital[i],z,2); // DIGITAL + z += 2; + i++; + } + } + j++; + } // 2 while + +} +/**************************************** End of File *******************************************************/ \ No newline at end of file diff --git a/resources/align_sort.h b/resources/align_sort.h new file mode 100644 index 0000000..3b6ab54 --- /dev/null +++ b/resources/align_sort.h @@ -0,0 +1,106 @@ +/* ----------------------------------------------------------------------------- + * align_sort.h + * + * iPDC - Phasor Data Concentrator + * + * Copyright (C) 2011-2012 Nitesh Pandit + * Copyright (C) 2011-2012 Kedar V. Khandeparkar + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: + * Nitesh Pandit + * Kedar V. Khandeparkar + * + * ----------------------------------------------------------------------------- */ + + +#define MAXTSB 5 +#define OLDFRAMECOUNT 5 + +/* ---------------------------------------------------------------- */ +/* global variable */ +/* ---------------------------------------------------------------- */ + +int front = -1; +int rear=-1; +int Tsb_Count = 0; + +/* ---------------------------------------------------------------- */ +/* global Data Structure */ +/* ---------------------------------------------------------------- */ + +/* Data Structure for Time Stamp Buffer */ +struct TimeStampBuffer { + + char *soc; + char *fracsec; + int count; // Current index + int num; // Total Number of PMUs + int counter; // Timer that will be initially set to 0 + int ready_to_send; + struct pmupdc_id_list *idlist; + struct data_frame *first_data_frame; + +}TSB[MAXTSB]; + +struct pmupdc_id_list { + + char *idcode; + int num_pmu; + struct pmupdc_id_list *nextid; +}; + +// Kedar K on 8/6/2013 +struct oldDataFramesTimeStampList +{ + unsigned int soc; + unsigned int fracsec; + +}ODFT[OLDFRAMECOUNT]; + +int old_df_front = -1; +int old_df_rear = -1; + +/* ---------------------------------------------------------------- */ +/* Function prototypes */ +/* ---------------------------------------------------------------- */ + +void time_align(struct data_frame *df); + +void assign_df_to_TSB(struct data_frame *df,int index); + +void dispatch(int index); + +void clear_TSB(int index); + +int create_dataframe(int index); + +void checkForMissingFrames(ENTRY*); + +int create_cfgframe(); + +void sort_data_inside_TSB(int index); + +struct data_frame* generate_dummy_dataframe(unsigned char *); + +void adjustOldFrameCount(int index); + +void intermediate_dispatch(int xx); + +int matchDataFrameTimeToTSBTime(unsigned int df_soc,unsigned int df_fracsec); + +void attacheEachDataFrame(struct data_frame *temp_df,int z); +/**************************************** End of File *******************************************************/ diff --git a/resources/applications.c b/resources/applications.c new file mode 100644 index 0000000..5cfdee8 --- /dev/null +++ b/resources/applications.c @@ -0,0 +1,724 @@ +/* ----------------------------------------------------------------------------- + * applications.c + * + * iPDC - Phasor Data Concentrator + * + * Copyright (C) 2011-2012 Nitesh Pandit + * Copyright (C) 2011-2012 Kedar V. Khandeparkar + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: + * Kedar V. Khandeparkar + * + * ----------------------------------------------------------------------------- */ + +#include +#include +#include +#include /* fabs */ +#include "parser.h" +#include "global.h" +#include "dallocate.h" +#include "applications.h" + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION averageFrequency(): */ +/* Computes average of frequency from all PMUs */ +/* ---------------------------------------------------------------------------- */ + +float averageFrequency(struct data_frame *df) { + + //struct data_frame *df = TSB[index].first_data_frame; + struct cfg_frame *temp_cfg = cfgfirst; + struct data_frame *temp_df; + float tempFreq = 0,avgFrequency; + int noOfPMU,i,j,count = 0; + + pthread_mutex_lock(&mutex_cfg); + + while(temp_cfg != NULL){ + + noOfPMU = to_intconvertor(temp_cfg->num_pmu); + count += noOfPMU; + temp_cfg = temp_cfg->cfgnext; + } + + for(i = 0;i<(count*10-100);i++) { + + temp_df = df; + temp_cfg = cfgfirst; + //printf("count = %d\n",count); + + while(temp_cfg != NULL){ + + noOfPMU = to_intconvertor(temp_cfg->num_pmu); + + if(temp_df != NULL) { + + for(j = 0;j < noOfPMU; j++) { + + //printf("a\n"); + if(temp_cfg->pmu[j]->fmt->freq == '1') { + + tempFreq += decode_ieee_single(temp_df->dpmu[j]->freq); + + } else { + + tempFreq += to_intconvertor(temp_df->dpmu[j]->freq); + } + } + temp_df = temp_df->dnext; + } + temp_cfg = temp_cfg->cfgnext; + } + } + pthread_mutex_unlock(&mutex_cfg); + + avgFrequency = tempFreq/count; + return avgFrequency; +} + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION frequencyInstability(): */ +/* Computes weighted average of frequency from some PMUs */ +/* ---------------------------------------------------------------------------- */ + +/*int frequencyInstability(struct data_frame *df) { + + //struct data_frame *df = TSB[index].first_data_frame; + struct cfg_frame *temp_cfg = cfgfirst; + + float tempFreq = 0,tempFc=0,totalFreq =0,totalHi=0; + float timeDiff = 20*1e-3; + float deltaFreq = 0; + int noOfPMUs = 0,totalPMUs=0,j; + + while(temp_cfg != NULL){ + + totalPMUs += to_intconvertor(temp_cfg->num_pmu); + temp_cfg = temp_cfg->cfgnext; + } + + int generatorPMUs = (totalPMUs*ratio) + 2; // Considered 1/5*noofPMUs+2 frequencies + int x = 0,*Hi; + Hi = randomGenerator(minHi,maxHi,generatorPMUs); + + temp_cfg = cfgfirst; + + while(temp_cfg != NULL) { + + noOfPMUs = to_intconvertor(temp_cfg->num_pmu); + + if(df != NULL) { + + for(j=0;jpmu[j]->fmt->freq == '1') { + + if(x == generatorPMUs) + break; + tempFreq = decode_ieee_single(df->dpmu[j]->freq); + totalFreq += Hi[x]*tempFreq; // Sum of Hi*fi (numerator) + totalHi += Hi[x]; // Sum of Hi (denominator) + x++; + } else { + + if(x == generatorPMUs) + break; + tempFreq = to_intconvertor(df->dpmu[j]->freq); + totalFreq += Hi[x]*tempFreq; // Sum of Hi*fi (numerator) + totalHi += Hi[x]; // Sum of Hi (denominator) + x++; + } + } + + df = df->dnext; + } + temp_cfg = temp_cfg->cfgnext; + } + + free(Hi); + + if(fc == 0) { + + fc = totalFreq/totalHi; + return 0; + + } else { + + tempFc = totalFreq/totalHi; + deltaFreq = fabs(fc-tempFc)/timeDiff; + /// Need to check deltaFreq < Threshold + fc = tempFc; + if(deltaFreq>delFThreshold) + return 1; + else return 0; + } +} +*/ + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION angleInstability(): */ +/* Computes angular deviations from center of inertia */ +/* ---------------------------------------------------------------------------- */ + +/*int angleInstability(struct data_frame *df) { + + //struct data_frame *df = TSB[index].first_data_frame + struct cfg_frame *temp_cfg = cfgfirst; + float totalPi,totalTheta,localAreaPi,*localAreaTheta; + int totalPMUs,noOfPMU,noOfAreas,noOfPMUsInOneArea,tempTotalPMUs,*localAreaPowerSchedule,*individualPowerSchedule; + + noOfPMUsInOneArea = 5; + totalPi= totalTheta =localAreaPi = 0; + + while(temp_cfg != NULL){ + + totalPMUs += to_intconvertor(temp_cfg->num_pmu); + temp_cfg = temp_cfg->cfgnext; + } + + tempTotalPMUs = totalPMUs; + float tt; + tt = (float)(totalPMUs*ratio)+2; // Number of areas eg 200*1/5+2 = 42 + noOfAreas = nearbyint(tt/noOfPMUsInOneArea); // 42/5 = 8.4 + int tt1 = (int)(noOfAreas); // 8 + int rem = nearbyint(tt%noOfPMUsInOneArea); + if(fabs(tt-tt1) >0) { //8.4 - 8 =0.4 + + noOfAreas++; // noOfAreas = 9 + } + + localAreaTheta = malloc((noOfAreas + 1)*sizeof(float)); + localAreaPowerSchedule = malloc((noOfAreas + 1)*sizeof(int)); + individualPowerSchedule = randomGenerator(minPi,maxPi,tt); + + temp_cfg = cfgfirst; + + float tempAreaAngle,tempAreaPower; + unsigned int phnmr,noOfPMUs,pType; + int x,y,z,i,j; // x to track no of areas and y to track no of generators in those areas z for individual generator schedule + i = j = x = y = z = 0; + tempAreaPower = tempAreaAngle = 0; + unsigned char *d,*fp_left,*fp_right,*fx_left,*fx_right,*phasorType,polar; + + fp_left = malloc(5*sizeof(unsigned char)); + fp_right = malloc(5*sizeof(unsigned char)); + fx_left = malloc(3*sizeof(unsigned char)); + fx_right = malloc(3*sizeof(unsigned char)); + phasorType = malloc(1*sizeof(unsigned char)); + + while(temp_cfg != NULL) { // Main Loop starts + + if(df != NULL) { + + noOfPMUs = to_intconvertor(temp_cfg->num_pmu); + + for(j = 0;j < noOfPMUs;j++) { + + phnmr = to_intconvertor(temp_cfg->pmu[j]->phnmr); + + if(phnmr != 0) { + + if(temp_cfg->pmu[j]->fmt->phasor == 1) { // Floating + + for(i = 0;ipmu[j]->phunit[i],1); + pType = to_intconvertor1(phasorType); + + if((pType == 0)&&(i%3 ==0)) { // pTYpe = 0 indicates V and only phase I is chosen with the assumption that 3 phase data is sent + + d = df->dpmu[j]->phasors[i]; + polar = temp_cfg->pmu[j]->fmt->polar; + tempAreaAngle += (getVoltagePhasorAngle(1,fp_left,fp_right,d,polar,temp_cfg,i,j)) * individualPowerSchedule[z]; // 1 -> floating pt + tempAreaPower += individualPowerSchedule[z]; + z++; + y++; + + if(y == rem && (x == noOfAreas - 1)) { + + localAreaTheta[x] = tempAreaAngle/tempAreaPower; + x++; + break; + + } else if(y == noOfPMUsInOneArea) { + + localAreaTheta[x] = tempAreaAngle/tempAreaPower; + y = 0; + x++; + } + } + } + + } else { // fixed point + + for(i = 0;i < phnmr; i++){ + + copy_cbyc (phasorType,(unsigned char *)temp_cfg->pmu[j]->phunit[i],1); + pType = to_intconvertor1(phasorType); + + if((pType == 0)&&(i%3 ==0)) { + + d = df->dpmu[j]->phasors[i]; + polar = temp_cfg->pmu[j]->fmt->polar; + tempAreaAngle += getVoltagePhasorAngle(0,fp_left,fp_right,d,polar,temp_cfg,i,j)* individualPowerSchedule[z]; // 0 -> fixed pt + tempAreaPower += individualPowerSchedule[z]; + z++; + y++; + + if(y == rem && (x == noOfAreas - 1)) { + + localAreaTheta[x] = tempAreaAngle/tempAreaPower; + localAreaPowerSchedule[x] = tempAreaPower; + x++; + break; + + } else if(y == noOfPMUsInOneArea) { + + localAreaTheta[x] = tempAreaAngle/tempAreaPower; + localAreaPowerSchedule[x] = tempAreaPower; + y = 0; + x++; + } + } + } + + } + } + } // if df ends + df = df->dnext; + } + temp_cfg = temp_cfg->cfgnext; + } // Main loop ends + + float centerAngle,totalPower; + centerAngle = totalPower = 0; + + for (i = 0;i angleThreshold) + violation[i] = '1'; + else + violation[i] = '0'; + } + + free(violation); + free(localAreaTheta); + free(localAreaPowerSchedule); + free(individualPowerSchedule); + free(fp_right); + free(fp_left); + free(fx_right); + free(fx_left); +} +*/ + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION voltagePhasorAggregation(): */ +/* Computes voltage phasor phasorAggregation */ +/* ---------------------------------------------------------------------------- */ + +/*float voltagePhasorAggregation(struct data_frame *df) { + + //struct data_frame *df = TSB[index].first_data_frame; + struct cfg_frame *temp_cfg = cfgfirst; + + int i,j,noOfPMUs,totalPMUs; + totalPMUs = i = j = 0; + + while(temp_cfg != NULL){ + + totalPMUs += to_intconvertor(temp_cfg->num_pmu); + temp_cfg = temp_cfg->cfgnext; + } + + int generatorPMUs = (totalPMUs*ratio) + 4; + temp_cfg = cfgfirst; + + unsigned int phnmr; + char polar; + float avgVoltageMagnitude = 0; + unsigned char *d; + int x = 0; + + unsigned char *fp_left,*fp_right,*fx_left,*fx_right,*phasorType; + fp_left = malloc(5*sizeof(unsigned char)); + fp_right = malloc(5*sizeof(unsigned char)); + fx_left = malloc(3*sizeof(unsigned char)); + fx_right = malloc(3*sizeof(unsigned char)); + phasorType = malloc(1*sizeof(unsigned char)); + + int pType; + + while(temp_cfg != NULL){ // Main Loop starts + + if(df != NULL) { + + noOfPMUs = to_intconvertor(temp_cfg->num_pmu); + + for(j=0;jpmu[j]->phnmr); + if(phnmr != 0) { + if(temp_cfg->pmu[j]->fmt->phasor == 1) { // Floating + + for(i = 0;ipmu[j]->phunit[i],1); + pType = to_intconvertor1(phasorType); + if((pType == 0) && (i%3 == 0)) { + + d = df->dpmu[j]->phasors[i]; + polar = temp_cfg->pmu[j]->fmt->polar; + avgVoltageMagnitude += getPhasorVolageMagnitude(1,fp_left,fp_right,d,polar,temp_cfg,i,j); // 1 -> floating pt + } + + } + x++; + if(x == generatorPMUs) + break; + } else { // fixed point + + for(i = 0;i < phnmr; i++){ + + copy_cbyc (phasorType,(unsigned char *)temp_cfg->pmu[j]->phunit[i],1); + pType = to_intconvertor1(phasorType); + if((pType == 0) && (i%3 == 0)) { + + d = df->dpmu[j]->phasors[i]; + polar = temp_cfg->pmu[j]->fmt->polar; + avgVoltageMagnitude += getPhasorVolageMagnitude(0,fp_left,fp_right,d,polar,temp_cfg,i,j); // 0 -> fixed pt + } + } + x++; + if(x == generatorPMUs) + break; + } + } + } + df = df->dnext; + } + temp_cfg = temp_cfg->cfgnext; + } // Main loop ends + + free(fp_right); + free(fp_left); + free(fx_right); + free(fx_left); + + return avgVoltageMagnitude; +} +*/ + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION randomGenerator(): */ +/* num random numbers array generated between min to max */ +/* ---------------------------------------------------------------------------- */ + +int * randomGenerator(int max,int min,int num) { + + int c =0,n,*coeff; + coeff = malloc((num+1)*sizeof(int)); + + while(1) { + + n = rand()%max + min; + + if(n>=min && n<= max) { + coeff[c] = n; + c++; + + if(c == num) + break; + } + } + return coeff; +} + +/* ---------------------------------------------------------------------------- */ +/* FUNCTION getVoltagePhasorAngle(): */ +/* get the phase angle */ +/* ---------------------------------------------------------------------------- */ + +/*float getVoltagePhasorAngle(int format,char left[],char right[],unsigned char *d,char polar,struct cfg_frame *temp_cfg,int i,int j) { + + float fp_r,fp_i,fp_angle; + unsigned int f_r,f_i; + + + if(format == 1) { // format indicates fixed or floating point + + memset(left,'\0',5); + memset(right,'\0',5); + //d = df->dpmu[j]->phasors[i]; + + copy_cbyc (left,d,4); + left[4] = '\0'; + d += 4; + + copy_cbyc(right,d,4); + right[4] = '\0'; + d += 4; + + fp_r = decode_ieee_single(left); + fp_i = decode_ieee_single(right); + + if(polar == '1') { // POLAR + + fp_angle = fp_i; + } else { // rectangular + + fp_angle = atan2f(fp_i, fp_r); + } + + } else { + + + memset(left,'\0',3); + memset(right,'\0',3); + + copy_cbyc (left,d,2); + left[2] = '\0'; + d += 2; + + copy_cbyc(right,d,2); + right[2] = '\0'; + d += 2; + + f_r = to_intconvertor(left); + f_i = to_intconvertor(right); + + if(polar == '1') { // POLAR + + fp_angle = f_i*1e-4; // Angle is in 10^4 radians + } else // RECTANGULAR + { + unsigned char *s = (unsigned char *)temp_cfg->pmu[j]->phunit[i]; + s++; + + unsigned char *buf = malloc(4*sizeof(unsigned char)); + copy_cbyc (buf,(unsigned char *)s,3); + buf[3] = '\0'; + unsigned long int l_phunit; + l_phunit = to_long_int_convertor1(buf); + l_phunit = l_phunit * 1e-5; + + fp_r = l_phunit *f_r; + fp_i = l_phunit *f_i; + + fp_angle = atan2f(fp_i, fp_r); + free(buf); + } + + } + return fp_angle; +} +*/ +/* ---------------------------------------------------------------------------- */ +/* FUNCTION getPhasorVolageMagnitude(): */ +/* get the phasor volage magnitude */ +/* ---------------------------------------------------------------------------- */ + +/*float getPhasorVolageMagnitude(int format,char left[],char right[],unsigned char *d,char polar,struct cfg_frame *temp_cfg,int i,int j) { + + float fp_r,fp_i,fp_magnitude; + unsigned int f_r,f_i; + + if(format == 1) { // format indicates fixed or floating point + + memset(left,'\0',5); + memset(right,'\0',5); + //d = df->dpmu[j]->phasors[i]; + + copy_cbyc (left,d,4); + left[4] = '\0'; + d += 4; + + copy_cbyc(right,d,4); + right[4] = '\0'; + d += 4; + + fp_r = decode_ieee_single(left); + fp_i = decode_ieee_single(right); + + if(polar == '1') { // POLAR + + fp_magnitude = fp_r; + } else { // rectangular + + fp_magnitude = sqrt(fp_i*fp_i + fp_r*fp_r); + } + + } else { + + + memset(left,'\0',3); + memset(right,'\0',3); + + copy_cbyc (left,d,2); + left[2] = '\0'; + d += 2; + + copy_cbyc(right,d,2); + right[2] = '\0'; + d += 2; + + f_r = to_intconvertor(left); + f_i = to_intconvertor(right); + + unsigned char *s = (unsigned char *)temp_cfg->pmu[j]->phunit[i]; + s++; + + unsigned char *buf = malloc(4*sizeof(unsigned char)); + copy_cbyc (buf,(unsigned char *)s,3); + buf[3] = '\0'; + unsigned long int l_phunit; + l_phunit = to_long_int_convertor1(buf); + l_phunit = l_phunit * 1e-5; + free(buf); + + if(polar == '1') { // POLAR + + fp_magnitude = f_r*l_phunit; + + } else // RECTANGULAR + { + fp_r = l_phunit *f_r; + fp_i = l_phunit *f_i; + + fp_magnitude = sqrt(fp_i*fp_i + fp_r*fp_r); + } + } + return fp_magnitude; +} +*/ +/* ---------------------------------------------------------------------------- */ +/* FUNCTION outOfStepDetection(): */ +/* angle deviations */ +/* ---------------------------------------------------------------------------- */ + +/*float outOfStepDetection(struct data_frame *df) { + + //struct data_frame *df = TSB[index].first_data_frame; + struct cfg_frame *temp_cfg = cfgfirst; + + int i,j,noOfPMUs,totalPMUs; + totalPMUs = i = j = 0; + + while(temp_cfg != NULL){ + + totalPMUs += to_intconvertor(temp_cfg->num_pmu); + temp_cfg = temp_cfg->cfgnext; + } + + int generatorPMUs = (totalPMUs*ratio); + if(generatorPMUs%2 == 1) + generatorPMUs +=1; + + temp_cfg = cfgfirst; + + if(OOSTD == '0') { + + delta = malloc((generatorPMUs+1)*sizeof(float)); + if(delta == NULL) + printf("no memory for delta\n"); + + slipFreuency = malloc((generatorPMUs+1)*sizeof(float)); + if(slipFreuency == NULL) + printf("no memory for slipFreuency\n"); + OOSTD = '1'; + } + + unsigned int phnmr; + char polar; + float phasorAngle = 0; + unsigned char *d; + int x = 0; + + unsigned char *fp_left,*fp_right,*fx_left,*fx_right,*phasorType; + fp_left = malloc(5*sizeof(unsigned char)); + fp_right = malloc(5*sizeof(unsigned char)); + fx_left = malloc(3*sizeof(unsigned char)); + fx_right = malloc(3*sizeof(unsigned char)); + phasorType = malloc(1*sizeof(unsigned char)); + + int pType; + + while(temp_cfg != NULL){ // Main Loop starts + + if(df != NULL) { + + noOfPMUs = to_intconvertor(temp_cfg->num_pmu); + + for(j=0;jpmu[j]->phnmr); + if(phnmr != 0) { + if(temp_cfg->pmu[j]->fmt->phasor == 1) { // Floating + + for(i = 0;ipmu[j]->phunit[i],1); + pType = to_intconvertor1(phasorType); + if((pType == 0) && (i%3 == 0)) { + + d = df->dpmu[j]->phasors[i]; + polar = temp_cfg->pmu[j]->fmt->polar; + phasorAngle = getVoltagePhasorAngle(1,fp_left,fp_right,d,polar,temp_cfg,i,j); // 1 -> floating pt + } + + } + x++; + if(x == generatorPMUs) + break; + } else { // fixed point + + for(i = 0;i < phnmr; i++){ + + copy_cbyc (phasorType,(unsigned char *)temp_cfg->pmu[j]->phunit[i],1); + pType = to_intconvertor1(phasorType); + if((pType == 0) && (i%3 == 0)) { + + d = df->dpmu[j]->phasors[i]; + polar = temp_cfg->pmu[j]->fmt->polar; + phasorAngle = getVoltagePhasorAngle(0,fp_left,fp_right,d,polar,temp_cfg,i,j); // 0 -> fixed pt + } + } + x++; + if(x == generatorPMUs) + break; + } + } + } + df = df->dnext; + } + temp_cfg = temp_cfg->cfgnext; + } // Main loop ends + + free(fp_right); + free(fp_left); + free(fx_right); + free(fx_left); + + return 0; +}*/ diff --git a/resources/applications.h b/resources/applications.h new file mode 100644 index 0000000..5e8b95b --- /dev/null +++ b/resources/applications.h @@ -0,0 +1,47 @@ +/* ----------------------------------------------------------------------------- + * applications.h + * + * iPDC - Phasor Data Concentrator + * + * Copyright (C) 2011-2012 Nitesh Pandit + * Copyright (C) 2011-2012 Kedar V. Khandeparkar + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * + * Authors: + * Kedar V. Khandeparkar + * + * ----------------------------------------------------------------------------- */ + +int minHi = 3,maxHi = 5; +int minPi = 100,maxPi = 500; +float fc = 0; +float delFThreshold = 0.3; +int angleThreshold = 20; +float ratio = 1/5; +float *delta,*slipFreuency; +char OOSTD = '0'; +//delta = 0; +//slipFreuency = 0; + + +float averageFrequency(struct data_frame *df); +int frequencyInstability(struct data_frame *df); +int angleInstability(struct data_frame *df); +float voltagePhasorAggregation(struct data_frame *df); +float outOfStepDetection(struct data_frame *df); +int * randomGenerator(int max,int min,int num); +float getVoltagePhasorAngle(int format,char left[],char right[],unsigned char *d,char polar,struct cfg_frame *temp_cfg,int i,int j); +float getPhasorVolageMagnitude(int format,char left[],char right[],unsigned char *d,char polar,struct cfg_frame *temp_cfg,int i,int j); \ No newline at end of file diff --git a/test-examples/examples/Makefile b/test-examples/examples/Makefile new file mode 100644 index 0000000..15472c3 --- /dev/null +++ b/test-examples/examples/Makefile @@ -0,0 +1,769 @@ +# Makefile.in generated by automake 1.16.5 from Makefile.am. +# examples/Makefile. Generated from Makefile.in by configure. + +# Copyright (C) 1994-2021 Free Software Foundation, Inc. + +# This Makefile.in is free software; the Free Software Foundation +# gives unlimited permission to copy and/or distribute it, +# with or without modifications, as long as this notice is preserved. + +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY, to the extent permitted by law; without +# even the implied warranty of MERCHANTABILITY or FITNESS FOR A +# PARTICULAR PURPOSE. + + + + +am__is_gnu_make = { \ + if test -z '$(MAKELEVEL)'; then \ + false; \ + elif test -n '$(MAKE_HOST)'; then \ + true; \ + elif test -n '$(MAKE_VERSION)' && test -n '$(CURDIR)'; then \ + true; \ + else \ + false; \ + fi; \ +} +am__make_running_with_option = \ + case $${target_option-} in \ + ?) ;; \ + *) echo "am__make_running_with_option: internal error: invalid" \ + "target option '$${target_option-}' specified" >&2; \ + exit 1;; \ + esac; \ + has_opt=no; \ + sane_makeflags=$$MAKEFLAGS; \ + if $(am__is_gnu_make); then \ + sane_makeflags=$$MFLAGS; \ + else \ + case $$MAKEFLAGS in \ + *\\[\ \ ]*) \ + bs=\\; \ + sane_makeflags=`printf '%s\n' "$$MAKEFLAGS" \ + | sed "s/$$bs$$bs[$$bs $$bs ]*//g"`;; \ + esac; \ + fi; \ + skip_next=no; \ + strip_trailopt () \ + { \ + flg=`printf '%s\n' "$$flg" | sed "s/$$1.*$$//"`; \ + }; \ + for flg in $$sane_makeflags; do \ + test $$skip_next = yes && { skip_next=no; continue; }; \ + case $$flg in \ + *=*|--*) continue;; \ + -*I) strip_trailopt 'I'; skip_next=yes;; \ + -*I?*) strip_trailopt 'I';; \ + -*O) strip_trailopt 'O'; skip_next=yes;; \ + -*O?*) strip_trailopt 'O';; \ + -*l) strip_trailopt 'l'; skip_next=yes;; \ + -*l?*) strip_trailopt 'l';; \ + -[dEDm]) skip_next=yes;; \ + -[JT]) skip_next=yes;; \ + esac; \ + case $$flg in \ + *$$target_option*) has_opt=yes; break;; \ + esac; \ + done; \ + test $$has_opt = yes +am__make_dryrun = (target_option=n; $(am__make_running_with_option)) +am__make_keepgoing = (target_option=k; $(am__make_running_with_option)) +pkgdatadir = $(datadir)/osm-gps-map +pkgincludedir = $(includedir)/osm-gps-map +pkglibdir = $(libdir)/osm-gps-map +pkglibexecdir = $(libexecdir)/osm-gps-map +am__cd = CDPATH="$${ZSH_VERSION+.}$(PATH_SEPARATOR)" && cd +install_sh_DATA = $(install_sh) -c -m 644 +install_sh_PROGRAM = $(install_sh) -c +install_sh_SCRIPT = $(install_sh) -c +INSTALL_HEADER = $(INSTALL_DATA) +transform = $(program_transform_name) +NORMAL_INSTALL = : +PRE_INSTALL = : +POST_INSTALL = : +NORMAL_UNINSTALL = : +PRE_UNINSTALL = : +POST_UNINSTALL = : +build_triplet = x86_64-pc-linux-gnu +host_triplet = x86_64-pc-linux-gnu +noinst_PROGRAMS = mapviewer$(EXEEXT) polygon$(EXEEXT) \ + editable_track$(EXEEXT) +subdir = examples +ACLOCAL_M4 = $(top_srcdir)/aclocal.m4 +am__aclocal_m4_deps = $(top_srcdir)/m4/ax_is_release.m4 \ + $(top_srcdir)/m4/ax_require_defined.m4 \ + $(top_srcdir)/m4/gtk-doc.m4 $(top_srcdir)/m4/introspection.m4 \ + $(top_srcdir)/m4/libtool.m4 $(top_srcdir)/m4/ltoptions.m4 \ + $(top_srcdir)/m4/ltsugar.m4 $(top_srcdir)/m4/ltversion.m4 \ + $(top_srcdir)/m4/lt~obsolete.m4 $(top_srcdir)/m4/pkg.m4 \ + $(top_srcdir)/configure.ac +am__configure_deps = $(am__aclocal_m4_deps) $(CONFIGURE_DEPENDENCIES) \ + $(ACLOCAL_M4) +DIST_COMMON = $(srcdir)/Makefile.am $(am__DIST_COMMON) +mkinstalldirs = $(install_sh) -d +CONFIG_HEADER = $(top_builddir)/config.h +CONFIG_CLEAN_FILES = +CONFIG_CLEAN_VPATH_FILES = +PROGRAMS = $(noinst_PROGRAMS) +am_editable_track_OBJECTS = editable_track-editable_track.$(OBJEXT) +editable_track_OBJECTS = $(am_editable_track_OBJECTS) +am__DEPENDENCIES_1 = +am__DEPENDENCIES_2 = $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) \ + $(am__DEPENDENCIES_1) $(am__DEPENDENCIES_1) +editable_track_DEPENDENCIES = $(am__DEPENDENCIES_2) \ + $(am__DEPENDENCIES_1) $(top_builddir)/src/libosmgpsmap-1.0.la +AM_V_lt = $(am__v_lt_$(V)) +am__v_lt_ = $(am__v_lt_$(AM_DEFAULT_VERBOSITY)) +am__v_lt_0 = --silent +am__v_lt_1 = +editable_track_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC \ + $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=link $(CCLD) \ + $(editable_track_CFLAGS) $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o \ + $@ +am_mapviewer_OBJECTS = mapviewer-mapviewer.$(OBJEXT) +mapviewer_OBJECTS = $(am_mapviewer_OBJECTS) +mapviewer_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ + $(top_builddir)/src/libosmgpsmap-1.0.la +mapviewer_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(mapviewer_CFLAGS) \ + $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +am_polygon_OBJECTS = polygon-polygon.$(OBJEXT) +polygon_OBJECTS = $(am_polygon_OBJECTS) +polygon_DEPENDENCIES = $(am__DEPENDENCIES_2) $(am__DEPENDENCIES_1) \ + $(top_builddir)/src/libosmgpsmap-1.0.la +polygon_LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(polygon_CFLAGS) \ + $(CFLAGS) $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_P = $(am__v_P_$(V)) +am__v_P_ = $(am__v_P_$(AM_DEFAULT_VERBOSITY)) +am__v_P_0 = false +am__v_P_1 = : +AM_V_GEN = $(am__v_GEN_$(V)) +am__v_GEN_ = $(am__v_GEN_$(AM_DEFAULT_VERBOSITY)) +am__v_GEN_0 = @echo " GEN " $@; +am__v_GEN_1 = +AM_V_at = $(am__v_at_$(V)) +am__v_at_ = $(am__v_at_$(AM_DEFAULT_VERBOSITY)) +am__v_at_0 = @ +am__v_at_1 = +DEFAULT_INCLUDES = -I. -I$(top_builddir) +depcomp = $(SHELL) $(top_srcdir)/depcomp +am__maybe_remake_depfiles = depfiles +am__depfiles_remade = ./$(DEPDIR)/editable_track-editable_track.Po \ + ./$(DEPDIR)/mapviewer-mapviewer.Po \ + ./$(DEPDIR)/polygon-polygon.Po +am__mv = mv -f +COMPILE = $(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) \ + $(CPPFLAGS) $(AM_CFLAGS) $(CFLAGS) +LTCOMPILE = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=compile $(CC) $(DEFS) \ + $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) \ + $(AM_CFLAGS) $(CFLAGS) +AM_V_CC = $(am__v_CC_$(V)) +am__v_CC_ = $(am__v_CC_$(AM_DEFAULT_VERBOSITY)) +am__v_CC_0 = @echo " CC " $@; +am__v_CC_1 = +CCLD = $(CC) +LINK = $(LIBTOOL) $(AM_V_lt) --tag=CC $(AM_LIBTOOLFLAGS) \ + $(LIBTOOLFLAGS) --mode=link $(CCLD) $(AM_CFLAGS) $(CFLAGS) \ + $(AM_LDFLAGS) $(LDFLAGS) -o $@ +AM_V_CCLD = $(am__v_CCLD_$(V)) +am__v_CCLD_ = $(am__v_CCLD_$(AM_DEFAULT_VERBOSITY)) +am__v_CCLD_0 = @echo " CCLD " $@; +am__v_CCLD_1 = +SOURCES = $(editable_track_SOURCES) $(mapviewer_SOURCES) \ + $(polygon_SOURCES) +DIST_SOURCES = $(editable_track_SOURCES) $(mapviewer_SOURCES) \ + $(polygon_SOURCES) +am__can_run_installinfo = \ + case $$AM_UPDATE_INFO_DIR in \ + n|no|NO) false;; \ + *) (install-info --version) >/dev/null 2>&1;; \ + esac +am__tagged_files = $(HEADERS) $(SOURCES) $(TAGS_FILES) $(LISP) +# Read a list of newline-separated strings from the standard input, +# and print each of them once, without duplicates. Input order is +# *not* preserved. +am__uniquify_input = $(AWK) '\ + BEGIN { nonempty = 0; } \ + { items[$$0] = 1; nonempty = 1; } \ + END { if (nonempty) { for (i in items) print i; }; } \ +' +# Make sure the list of sources is unique. This is necessary because, +# e.g., the same source file might be shared among _SOURCES variables +# for different programs/libraries. +am__define_uniq_tagged_files = \ + list='$(am__tagged_files)'; \ + unique=`for i in $$list; do \ + if test -f "$$i"; then echo $$i; else echo $(srcdir)/$$i; fi; \ + done | $(am__uniquify_input)` +am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/depcomp README +DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) +ACLOCAL = ${SHELL} '/home/chasingcar/dev/osm-gps-map/missing' aclocal-1.16 +AMTAR = $${TAR-tar} +AM_DEFAULT_VERBOSITY = 0 +AR = ar +AS = as +AUTOCONF = ${SHELL} '/home/chasingcar/dev/osm-gps-map/missing' autoconf +AUTOHEADER = ${SHELL} '/home/chasingcar/dev/osm-gps-map/missing' autoheader +AUTOMAKE = ${SHELL} '/home/chasingcar/dev/osm-gps-map/missing' automake-1.16 +AWK = mawk +CAIRO_CFLAGS = -I/usr/include/cairo -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/libpng16 +CAIRO_LIBS = -lcairo +CC = gcc +CCDEPMODE = depmode=gcc3 +CFLAGS = -g -O2 +CPPFLAGS = +CSCOPE = cscope +CTAGS = ctags +CYGPATH_W = echo +DEFS = -DHAVE_CONFIG_H +DEPDIR = .deps +DLLTOOL = dlltool +DSYMUTIL = +DUMPBIN = +ECHO_C = +ECHO_N = -n +ECHO_T = +EGREP = /usr/bin/grep -E +ETAGS = etags +EXEEXT = +FGREP = /usr/bin/grep -F +GLIB_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include +GLIB_LIBS = -lglib-2.0 +GREP = /usr/bin/grep +GTHREAD_CFLAGS = -pthread -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include +GTHREAD_LIBS = -lgthread-2.0 -pthread -lglib-2.0 +GTKDOC_CHECK = gtkdoc-check.test +GTKDOC_CHECK_PATH = /usr/bin/gtkdoc-check +GTKDOC_DEPS_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include +GTKDOC_DEPS_LIBS = -lgobject-2.0 -lglib-2.0 +GTKDOC_MKPDF = /usr/bin/gtkdoc-mkpdf +GTKDOC_REBASE = /usr/bin/gtkdoc-rebase +GTK_CFLAGS = -pthread -I/usr/include/gtk-3.0 -I/usr/include/at-spi2-atk/2.0 -I/usr/include/at-spi-2.0 -I/usr/include/dbus-1.0 -I/usr/lib/x86_64-linux-gnu/dbus-1.0/include -I/usr/include/gtk-3.0 -I/usr/include/gio-unix-2.0 -I/usr/include/cairo -I/usr/include/pango-1.0 -I/usr/include/harfbuzz -I/usr/include/pango-1.0 -I/usr/include/fribidi -I/usr/include/harfbuzz -I/usr/include/atk-1.0 -I/usr/include/cairo -I/usr/include/pixman-1 -I/usr/include/uuid -I/usr/include/freetype2 -I/usr/include/gdk-pixbuf-2.0 -I/usr/include/libpng16 -I/usr/include/x86_64-linux-gnu -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include +GTK_LIBS = -lgtk-3 -lgdk-3 -lpangocairo-1.0 -lpango-1.0 -lharfbuzz -latk-1.0 -lcairo-gobject -lcairo -lgdk_pixbuf-2.0 -lgio-2.0 -lgobject-2.0 -lglib-2.0 +HTML_DIR = ${datadir}/gtk-doc/html +INSTALL = /usr/bin/install -c +INSTALL_DATA = ${INSTALL} -m 644 +INSTALL_PROGRAM = ${INSTALL} +INSTALL_SCRIPT = ${INSTALL} +INSTALL_STRIP_PROGRAM = $(install_sh) -c -s +INTROSPECTION_CFLAGS = -I/usr/include/gobject-introspection-1.0 -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include +INTROSPECTION_COMPILER = /usr/bin/g-ir-compiler +INTROSPECTION_GENERATE = /usr/bin/g-ir-generate +INTROSPECTION_GIRDIR = /usr/local/share/gir-1.0 +INTROSPECTION_LIBS = -lgirepository-1.0 -lgobject-2.0 -lglib-2.0 +INTROSPECTION_MAKEFILE = /usr/share/gobject-introspection-1.0/Makefile.introspection +INTROSPECTION_SCANNER = /usr/bin/g-ir-scanner +INTROSPECTION_TYPELIBDIR = /usr/local/lib/girepository-1.0 +LD = /usr/bin/ld -m elf_x86_64 +LDFLAGS = +LIBOBJS = +LIBS = +LIBTOOL = $(SHELL) $(top_builddir)/libtool +LIPO = +LN_S = ln -s +LTLIBOBJS = +LT_SYS_LIBRARY_PATH = +LT_VERSION_INFO = 2:1:1 +MAKEINFO = ${SHELL} '/home/chasingcar/dev/osm-gps-map/missing' makeinfo +MANIFEST_TOOL = : +MKDIR_P = /usr/bin/mkdir -p +NM = /usr/bin/nm -B +NMEDIT = +OBJDUMP = objdump +OBJEXT = o +OTOOL = +OTOOL64 = +PACKAGE = osm-gps-map +PACKAGE_BUGREPORT = http://github.com/nzjrs/osm-gps-map/issues +PACKAGE_NAME = osm-gps-map +PACKAGE_STRING = osm-gps-map 1.2.1 +PACKAGE_TARNAME = osm-gps-map +PACKAGE_URL = +PACKAGE_VERSION = 1.2.1 +PATH_SEPARATOR = : +PKG_CONFIG = /usr/bin/pkg-config +PKG_CONFIG_LIBDIR = +PKG_CONFIG_PATH = +RANLIB = ranlib +SED = /usr/bin/sed +SET_MAKE = +SHELL = /bin/bash +SOUP24_CFLAGS = -pthread -I/usr/include/libsoup-2.4 -I/usr/include/libxml2 -I/usr/include/libmount -I/usr/include/blkid -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include +SOUP24_LIBS = -lsoup-2.4 -Wl,--export-dynamic -lgmodule-2.0 -pthread -lgio-2.0 -lgobject-2.0 -lglib-2.0 +STRIP = strip +VERSION = 1.2.1 +_GI_EXP_DATADIR = /usr/local/share +_GI_EXP_LIBDIR = /usr/local/lib +abs_builddir = /home/chasingcar/dev/osm-gps-map/examples +abs_srcdir = /home/chasingcar/dev/osm-gps-map/examples +abs_top_builddir = /home/chasingcar/dev/osm-gps-map +abs_top_srcdir = /home/chasingcar/dev/osm-gps-map +ac_ct_AR = ar +ac_ct_CC = gcc +ac_ct_DUMPBIN = +am__include = include +am__leading_dot = . +am__quote = +am__tar = $${TAR-tar} chof - "$$tardir" +am__untar = $${TAR-tar} xf - +bindir = ${exec_prefix}/bin +build = x86_64-pc-linux-gnu +build_alias = +build_cpu = x86_64 +build_os = linux-gnu +build_vendor = pc +builddir = . +datadir = ${datarootdir} +datarootdir = ${prefix}/share +docdir = ${datarootdir}/doc/${PACKAGE_TARNAME} +dvidir = ${docdir} +exec_prefix = ${prefix} +host = x86_64-pc-linux-gnu +host_alias = +host_cpu = x86_64 +host_os = linux-gnu +host_vendor = pc +htmldir = ${docdir} +includedir = ${prefix}/include +infodir = ${datarootdir}/info +install_sh = ${SHELL} /home/chasingcar/dev/osm-gps-map/install-sh +libdir = ${exec_prefix}/lib +libexecdir = ${exec_prefix}/libexec +localedir = ${datarootdir}/locale +localstatedir = ${prefix}/var +mandir = ${datarootdir}/man +mkdir_p = $(MKDIR_P) +oldincludedir = /usr/include +pdfdir = ${docdir} +prefix = /usr/local +program_transform_name = s,x,x, +psdir = ${docdir} +runstatedir = ${localstatedir}/run +sbindir = ${exec_prefix}/sbin +sharedstatedir = ${prefix}/com +srcdir = . +sysconfdir = ${prefix}/etc +target_alias = +top_build_prefix = ../ +top_builddir = .. +top_srcdir = .. +OSMGPSMAP_CFLAGS = \ + $(GLIB_CFLAGS) \ + $(GTK_CFLAGS) \ + $(CAIRO_CFLAGS) \ + $(SOUP24_CFLAGS) + +OSMGPSMAP_LIBS = \ + $(GLIB_LIBS) \ + $(GTK_LIBS) \ + $(CAIRO_LIBS) \ + $(SOUP24_LIBS) + +mapviewer_SOURCES = \ + mapviewer.c + +mapviewer_CFLAGS = \ + -I$(top_srcdir)/src \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) \ + $(OSMGPSMAP_CFLAGS) \ + $(GTHREAD_CFLAGS) + +mapviewer_LDADD = \ + $(OSMGPSMAP_LIBS) \ + $(GTHREAD_LIBS) \ + $(top_builddir)/src/libosmgpsmap-1.0.la + +polygon_SOURCES = \ + polygon.c + +polygon_CFLAGS = \ + -I$(top_srcdir)/src \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) \ + $(OSMGPSMAP_CFLAGS) \ + $(GTHREAD_CFLAGS) + +polygon_LDADD = \ + $(OSMGPSMAP_LIBS) \ + $(GTHREAD_LIBS) \ + $(top_builddir)/src/libosmgpsmap-1.0.la + +editable_track_SOURCES = \ + editable_track.c + +editable_track_CFLAGS = \ + -I$(top_srcdir)/src \ + $(WARN_CFLAGS) \ + $(DISABLE_DEPRECATED) \ + $(OSMGPSMAP_CFLAGS) \ + $(GTHREAD_CFLAGS) + +editable_track_LDADD = \ + $(OSMGPSMAP_LIBS) \ + $(GTHREAD_LIBS) \ + $(top_builddir)/src/libosmgpsmap-1.0.la + +EXTRA_DIST = poi.png mapviewer.ui mapviewer.js README +all: all-am + +.SUFFIXES: +.SUFFIXES: .c .lo .o .obj +$(srcdir)/Makefile.in: $(srcdir)/Makefile.am $(am__configure_deps) + @for dep in $?; do \ + case '$(am__configure_deps)' in \ + *$$dep*) \ + ( cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh ) \ + && { if test -f $@; then exit 0; else break; fi; }; \ + exit 1;; \ + esac; \ + done; \ + echo ' cd $(top_srcdir) && $(AUTOMAKE) --foreign examples/Makefile'; \ + $(am__cd) $(top_srcdir) && \ + $(AUTOMAKE) --foreign examples/Makefile +Makefile: $(srcdir)/Makefile.in $(top_builddir)/config.status + @case '$?' in \ + *config.status*) \ + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh;; \ + *) \ + echo ' cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles)'; \ + cd $(top_builddir) && $(SHELL) ./config.status $(subdir)/$@ $(am__maybe_remake_depfiles);; \ + esac; + +$(top_builddir)/config.status: $(top_srcdir)/configure $(CONFIG_STATUS_DEPENDENCIES) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh + +$(top_srcdir)/configure: $(am__configure_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(ACLOCAL_M4): $(am__aclocal_m4_deps) + cd $(top_builddir) && $(MAKE) $(AM_MAKEFLAGS) am--refresh +$(am__aclocal_m4_deps): + +clean-noinstPROGRAMS: + @list='$(noinst_PROGRAMS)'; test -n "$$list" || exit 0; \ + echo " rm -f" $$list; \ + rm -f $$list || exit $$?; \ + test -n "$(EXEEXT)" || exit 0; \ + list=`for p in $$list; do echo "$$p"; done | sed 's/$(EXEEXT)$$//'`; \ + echo " rm -f" $$list; \ + rm -f $$list + +editable_track$(EXEEXT): $(editable_track_OBJECTS) $(editable_track_DEPENDENCIES) $(EXTRA_editable_track_DEPENDENCIES) + @rm -f editable_track$(EXEEXT) + $(AM_V_CCLD)$(editable_track_LINK) $(editable_track_OBJECTS) $(editable_track_LDADD) $(LIBS) + +mapviewer$(EXEEXT): $(mapviewer_OBJECTS) $(mapviewer_DEPENDENCIES) $(EXTRA_mapviewer_DEPENDENCIES) + @rm -f mapviewer$(EXEEXT) + $(AM_V_CCLD)$(mapviewer_LINK) $(mapviewer_OBJECTS) $(mapviewer_LDADD) $(LIBS) + +polygon$(EXEEXT): $(polygon_OBJECTS) $(polygon_DEPENDENCIES) $(EXTRA_polygon_DEPENDENCIES) + @rm -f polygon$(EXEEXT) + $(AM_V_CCLD)$(polygon_LINK) $(polygon_OBJECTS) $(polygon_LDADD) $(LIBS) + +mostlyclean-compile: + -rm -f *.$(OBJEXT) + +distclean-compile: + -rm -f *.tab.c + +include ./$(DEPDIR)/editable_track-editable_track.Po # am--include-marker +include ./$(DEPDIR)/mapviewer-mapviewer.Po # am--include-marker +include ./$(DEPDIR)/polygon-polygon.Po # am--include-marker + +$(am__depfiles_remade): + @$(MKDIR_P) $(@D) + @echo '# dummy' >$@-t && $(am__mv) $@-t $@ + +am--depfiles: $(am__depfiles_remade) + +.c.o: + $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.o$$||'`;\ + $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + $(am__mv) $$depbase.Tpo $$depbase.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ $< + +.c.obj: + $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.obj$$||'`;\ + $(COMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ `$(CYGPATH_W) '$<'` &&\ + $(am__mv) $$depbase.Tpo $$depbase.Po +# $(AM_V_CC)source='$<' object='$@' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(COMPILE) -c -o $@ `$(CYGPATH_W) '$<'` + +.c.lo: + $(AM_V_CC)depbase=`echo $@ | sed 's|[^/]*$$|$(DEPDIR)/&|;s|\.lo$$||'`;\ + $(LTCOMPILE) -MT $@ -MD -MP -MF $$depbase.Tpo -c -o $@ $< &&\ + $(am__mv) $$depbase.Tpo $$depbase.Plo +# $(AM_V_CC)source='$<' object='$@' libtool=yes \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(LTCOMPILE) -c -o $@ $< + +editable_track-editable_track.o: editable_track.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(editable_track_CFLAGS) $(CFLAGS) -MT editable_track-editable_track.o -MD -MP -MF $(DEPDIR)/editable_track-editable_track.Tpo -c -o editable_track-editable_track.o `test -f 'editable_track.c' || echo '$(srcdir)/'`editable_track.c + $(AM_V_at)$(am__mv) $(DEPDIR)/editable_track-editable_track.Tpo $(DEPDIR)/editable_track-editable_track.Po +# $(AM_V_CC)source='editable_track.c' object='editable_track-editable_track.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(editable_track_CFLAGS) $(CFLAGS) -c -o editable_track-editable_track.o `test -f 'editable_track.c' || echo '$(srcdir)/'`editable_track.c + +editable_track-editable_track.obj: editable_track.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(editable_track_CFLAGS) $(CFLAGS) -MT editable_track-editable_track.obj -MD -MP -MF $(DEPDIR)/editable_track-editable_track.Tpo -c -o editable_track-editable_track.obj `if test -f 'editable_track.c'; then $(CYGPATH_W) 'editable_track.c'; else $(CYGPATH_W) '$(srcdir)/editable_track.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/editable_track-editable_track.Tpo $(DEPDIR)/editable_track-editable_track.Po +# $(AM_V_CC)source='editable_track.c' object='editable_track-editable_track.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(editable_track_CFLAGS) $(CFLAGS) -c -o editable_track-editable_track.obj `if test -f 'editable_track.c'; then $(CYGPATH_W) 'editable_track.c'; else $(CYGPATH_W) '$(srcdir)/editable_track.c'; fi` + +mapviewer-mapviewer.o: mapviewer.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mapviewer_CFLAGS) $(CFLAGS) -MT mapviewer-mapviewer.o -MD -MP -MF $(DEPDIR)/mapviewer-mapviewer.Tpo -c -o mapviewer-mapviewer.o `test -f 'mapviewer.c' || echo '$(srcdir)/'`mapviewer.c + $(AM_V_at)$(am__mv) $(DEPDIR)/mapviewer-mapviewer.Tpo $(DEPDIR)/mapviewer-mapviewer.Po +# $(AM_V_CC)source='mapviewer.c' object='mapviewer-mapviewer.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mapviewer_CFLAGS) $(CFLAGS) -c -o mapviewer-mapviewer.o `test -f 'mapviewer.c' || echo '$(srcdir)/'`mapviewer.c + +mapviewer-mapviewer.obj: mapviewer.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mapviewer_CFLAGS) $(CFLAGS) -MT mapviewer-mapviewer.obj -MD -MP -MF $(DEPDIR)/mapviewer-mapviewer.Tpo -c -o mapviewer-mapviewer.obj `if test -f 'mapviewer.c'; then $(CYGPATH_W) 'mapviewer.c'; else $(CYGPATH_W) '$(srcdir)/mapviewer.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/mapviewer-mapviewer.Tpo $(DEPDIR)/mapviewer-mapviewer.Po +# $(AM_V_CC)source='mapviewer.c' object='mapviewer-mapviewer.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(mapviewer_CFLAGS) $(CFLAGS) -c -o mapviewer-mapviewer.obj `if test -f 'mapviewer.c'; then $(CYGPATH_W) 'mapviewer.c'; else $(CYGPATH_W) '$(srcdir)/mapviewer.c'; fi` + +polygon-polygon.o: polygon.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(polygon_CFLAGS) $(CFLAGS) -MT polygon-polygon.o -MD -MP -MF $(DEPDIR)/polygon-polygon.Tpo -c -o polygon-polygon.o `test -f 'polygon.c' || echo '$(srcdir)/'`polygon.c + $(AM_V_at)$(am__mv) $(DEPDIR)/polygon-polygon.Tpo $(DEPDIR)/polygon-polygon.Po +# $(AM_V_CC)source='polygon.c' object='polygon-polygon.o' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(polygon_CFLAGS) $(CFLAGS) -c -o polygon-polygon.o `test -f 'polygon.c' || echo '$(srcdir)/'`polygon.c + +polygon-polygon.obj: polygon.c + $(AM_V_CC)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(polygon_CFLAGS) $(CFLAGS) -MT polygon-polygon.obj -MD -MP -MF $(DEPDIR)/polygon-polygon.Tpo -c -o polygon-polygon.obj `if test -f 'polygon.c'; then $(CYGPATH_W) 'polygon.c'; else $(CYGPATH_W) '$(srcdir)/polygon.c'; fi` + $(AM_V_at)$(am__mv) $(DEPDIR)/polygon-polygon.Tpo $(DEPDIR)/polygon-polygon.Po +# $(AM_V_CC)source='polygon.c' object='polygon-polygon.obj' libtool=no \ +# DEPDIR=$(DEPDIR) $(CCDEPMODE) $(depcomp) \ +# $(AM_V_CC_no)$(CC) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(AM_CPPFLAGS) $(CPPFLAGS) $(polygon_CFLAGS) $(CFLAGS) -c -o polygon-polygon.obj `if test -f 'polygon.c'; then $(CYGPATH_W) 'polygon.c'; else $(CYGPATH_W) '$(srcdir)/polygon.c'; fi` + +mostlyclean-libtool: + -rm -f *.lo + +clean-libtool: + -rm -rf .libs _libs + +ID: $(am__tagged_files) + $(am__define_uniq_tagged_files); mkid -fID $$unique +tags: tags-am +TAGS: tags + +tags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + set x; \ + here=`pwd`; \ + $(am__define_uniq_tagged_files); \ + shift; \ + if test -z "$(ETAGS_ARGS)$$*$$unique"; then :; else \ + test -n "$$unique" || unique=$$empty_fix; \ + if test $$# -gt 0; then \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + "$$@" $$unique; \ + else \ + $(ETAGS) $(ETAGSFLAGS) $(AM_ETAGSFLAGS) $(ETAGS_ARGS) \ + $$unique; \ + fi; \ + fi +ctags: ctags-am + +CTAGS: ctags +ctags-am: $(TAGS_DEPENDENCIES) $(am__tagged_files) + $(am__define_uniq_tagged_files); \ + test -z "$(CTAGS_ARGS)$$unique" \ + || $(CTAGS) $(CTAGSFLAGS) $(AM_CTAGSFLAGS) $(CTAGS_ARGS) \ + $$unique + +GTAGS: + here=`$(am__cd) $(top_builddir) && pwd` \ + && $(am__cd) $(top_srcdir) \ + && gtags -i $(GTAGS_ARGS) "$$here" +cscopelist: cscopelist-am + +cscopelist-am: $(am__tagged_files) + list='$(am__tagged_files)'; \ + case "$(srcdir)" in \ + [\\/]* | ?:[\\/]*) sdir="$(srcdir)" ;; \ + *) sdir=$(subdir)/$(srcdir) ;; \ + esac; \ + for i in $$list; do \ + if test -f "$$i"; then \ + echo "$(subdir)/$$i"; \ + else \ + echo "$$sdir/$$i"; \ + fi; \ + done >> $(top_builddir)/cscope.files + +distclean-tags: + -rm -f TAGS ID GTAGS GRTAGS GSYMS GPATH tags +distdir: $(BUILT_SOURCES) + $(MAKE) $(AM_MAKEFLAGS) distdir-am + +distdir-am: $(DISTFILES) + @srcdirstrip=`echo "$(srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + topsrcdirstrip=`echo "$(top_srcdir)" | sed 's/[].[^$$\\*]/\\\\&/g'`; \ + list='$(DISTFILES)'; \ + dist_files=`for file in $$list; do echo $$file; done | \ + sed -e "s|^$$srcdirstrip/||;t" \ + -e "s|^$$topsrcdirstrip/|$(top_builddir)/|;t"`; \ + case $$dist_files in \ + */*) $(MKDIR_P) `echo "$$dist_files" | \ + sed '/\//!d;s|^|$(distdir)/|;s,/[^/]*$$,,' | \ + sort -u` ;; \ + esac; \ + for file in $$dist_files; do \ + if test -f $$file || test -d $$file; then d=.; else d=$(srcdir); fi; \ + if test -d $$d/$$file; then \ + dir=`echo "/$$file" | sed -e 's,/[^/]*$$,,'`; \ + if test -d "$(distdir)/$$file"; then \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + if test -d $(srcdir)/$$file && test $$d != $(srcdir); then \ + cp -fpR $(srcdir)/$$file "$(distdir)$$dir" || exit 1; \ + find "$(distdir)/$$file" -type d ! -perm -700 -exec chmod u+rwx {} \;; \ + fi; \ + cp -fpR $$d/$$file "$(distdir)$$dir" || exit 1; \ + else \ + test -f "$(distdir)/$$file" \ + || cp -p $$d/$$file "$(distdir)/$$file" \ + || exit 1; \ + fi; \ + done +check-am: all-am +check: check-am +all-am: Makefile $(PROGRAMS) +installdirs: +install: install-am +install-exec: install-exec-am +install-data: install-data-am +uninstall: uninstall-am + +install-am: all-am + @$(MAKE) $(AM_MAKEFLAGS) install-exec-am install-data-am + +installcheck: installcheck-am +install-strip: + if test -z '$(STRIP)'; then \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + install; \ + else \ + $(MAKE) $(AM_MAKEFLAGS) INSTALL_PROGRAM="$(INSTALL_STRIP_PROGRAM)" \ + install_sh_PROGRAM="$(INSTALL_STRIP_PROGRAM)" INSTALL_STRIP_FLAG=-s \ + "INSTALL_PROGRAM_ENV=STRIPPROG='$(STRIP)'" install; \ + fi +mostlyclean-generic: + +clean-generic: + +distclean-generic: + -test -z "$(CONFIG_CLEAN_FILES)" || rm -f $(CONFIG_CLEAN_FILES) + -test . = "$(srcdir)" || test -z "$(CONFIG_CLEAN_VPATH_FILES)" || rm -f $(CONFIG_CLEAN_VPATH_FILES) + +maintainer-clean-generic: + @echo "This command is intended for maintainers to use" + @echo "it deletes files that may require special tools to rebuild." +clean: clean-am + +clean-am: clean-generic clean-libtool clean-noinstPROGRAMS \ + mostlyclean-am + +distclean: distclean-am + -rm -f ./$(DEPDIR)/editable_track-editable_track.Po + -rm -f ./$(DEPDIR)/mapviewer-mapviewer.Po + -rm -f ./$(DEPDIR)/polygon-polygon.Po + -rm -f Makefile +distclean-am: clean-am distclean-compile distclean-generic \ + distclean-tags + +dvi: dvi-am + +dvi-am: + +html: html-am + +html-am: + +info: info-am + +info-am: + +install-data-am: + +install-dvi: install-dvi-am + +install-dvi-am: + +install-exec-am: + +install-html: install-html-am + +install-html-am: + +install-info: install-info-am + +install-info-am: + +install-man: + +install-pdf: install-pdf-am + +install-pdf-am: + +install-ps: install-ps-am + +install-ps-am: + +installcheck-am: + +maintainer-clean: maintainer-clean-am + -rm -f ./$(DEPDIR)/editable_track-editable_track.Po + -rm -f ./$(DEPDIR)/mapviewer-mapviewer.Po + -rm -f ./$(DEPDIR)/polygon-polygon.Po + -rm -f Makefile +maintainer-clean-am: distclean-am maintainer-clean-generic + +mostlyclean: mostlyclean-am + +mostlyclean-am: mostlyclean-compile mostlyclean-generic \ + mostlyclean-libtool + +pdf: pdf-am + +pdf-am: + +ps: ps-am + +ps-am: + +uninstall-am: + +.MAKE: install-am install-strip + +.PHONY: CTAGS GTAGS TAGS all all-am am--depfiles check check-am clean \ + clean-generic clean-libtool clean-noinstPROGRAMS cscopelist-am \ + ctags ctags-am distclean distclean-compile distclean-generic \ + distclean-libtool distclean-tags distdir dvi dvi-am html \ + html-am info info-am install install-am install-data \ + install-data-am install-dvi install-dvi-am install-exec \ + install-exec-am install-html install-html-am install-info \ + install-info-am install-man install-pdf install-pdf-am \ + install-ps install-ps-am install-strip installcheck \ + installcheck-am installdirs maintainer-clean \ + maintainer-clean-generic mostlyclean mostlyclean-compile \ + mostlyclean-generic mostlyclean-libtool pdf pdf-am ps ps-am \ + tags tags-am uninstall uninstall-am + +.PRECIOUS: Makefile + + +# Tell versions [3.59,3.63) of GNU make to not export all variables. +# Otherwise a system limit (for SysV at least) may be exceeded. +.NOEXPORT: diff --git a/test-examples/examples/README b/test-examples/examples/README new file mode 100644 index 0000000..1ccb183 --- /dev/null +++ b/test-examples/examples/README @@ -0,0 +1,17 @@ +osm-gps-map example applications + * ./mapviewer + C based demo app with many options. See '--help' for a list. Note, this + must be executed from the examples directory so it can find the mapviewer.ui + file. + * ./polygon + This example demonstrates editable polygons. Vertex points can be dragged. + Clicking mid-points divides the line and creates another vertex. + * ./mapviewer.py + Python version of the C demo app, with examples showing how to do custom + layers. + * ./mapviewer.js + Javascript example using seed + gobject-introspection. If running uninstalled, + you probbably need to tell GObject introspection where to find the + bindings. Do the following from the example directory + # export LD_LIBRARY_PATH=../src/.libs/ + # export GI_TYPELIB_PATH=../src/ diff --git a/test-examples/examples/editable_track.c b/test-examples/examples/editable_track.c new file mode 100644 index 0000000..07613aa --- /dev/null +++ b/test-examples/examples/editable_track.c @@ -0,0 +1,42 @@ +#include +#include "osm-gps-map.h" + +int +main (int argc, + char *argv[]) +{ + OsmGpsMap *map; + GtkWidget *window; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Window"); + g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + + + map = g_object_new (OSM_TYPE_GPS_MAP, NULL); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(map)); + + OsmGpsMapTrack* track = osm_gps_map_track_new(); + + OsmGpsMapPoint* p1, *p2; + p1 = osm_gps_map_point_new_radians(1.25663706, -0.488692191); + p2 = osm_gps_map_point_new_radians(1.06465084, -0.750491578); + + osm_gps_map_track_add_point(track, p1); + osm_gps_map_track_add_point(track, p2); + + g_object_set(track, "editable", TRUE, NULL); + + osm_gps_map_track_add(map, track); + + gtk_widget_show (GTK_WIDGET(map)); + gtk_widget_show (window); + + gtk_main (); + + return 0; +} + + diff --git a/test-examples/examples/env.sh b/test-examples/examples/env.sh new file mode 100755 index 0000000..9c4a8f0 --- /dev/null +++ b/test-examples/examples/env.sh @@ -0,0 +1,7 @@ +#!/bin/sh + +export LD_LIBRARY_PATH=../src/.libs/ +export GI_TYPELIB_PATH=$GI_TYPELIB_PATH:../src/ +export PYTHONPATH=../python/ + +$1 diff --git a/test-examples/examples/mapviewer.c b/test-examples/examples/mapviewer.c new file mode 100644 index 0000000..32975aa --- /dev/null +++ b/test-examples/examples/mapviewer.c @@ -0,0 +1,450 @@ +/* -*- Mode: C; indent-tabs-mode: nil; c-basic-offset: 4; tab-width: 4 -*- */ +/* vim:set et sw=4 ts=4 cino=t0,(0: */ +/* + * main.c + * Copyright (C) John Stowers 2008 + * + * This is free software: you can redistribute it and/or modify it + * under the terms of the GNU General Public License + * as published by the Free Software Foundation; version 2. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, see . + */ + +#include +#include +#include +#include +#include + +#include "osm-gps-map.h" + +static OsmGpsMapSource_t opt_map_provider = OSM_GPS_MAP_SOURCE_OPENSTREETMAP; +static gboolean opt_friendly_cache = FALSE; +static gboolean opt_no_cache = FALSE; +static char *opt_cache_base_dir = NULL; +static gboolean opt_editable_tracks = FALSE; +static GOptionEntry entries[] = + { + {"friendly-cache", 'f', 0, G_OPTION_ARG_NONE, &opt_friendly_cache, "Store maps using friendly cache style (source name)", NULL}, + {"no-cache", 'n', 0, G_OPTION_ARG_NONE, &opt_no_cache, "Disable cache", NULL}, + {"cache-basedir", 'b', 0, G_OPTION_ARG_FILENAME, &opt_cache_base_dir, "Cache basedir", NULL}, + {"map", 'm', 0, G_OPTION_ARG_INT, &opt_map_provider, "Map source", "N"}, + {"editable-tracks", 'e', 0, G_OPTION_ARG_NONE, &opt_editable_tracks, "Make the tracks editable", NULL}, + {NULL}}; + +#if !GTK_CHECK_VERSION(3, 22, 0) +// use --gtk-debug=updates instead on newer GTK +static gboolean opt_debug = FALSE; +static GOptionEntry debug_entries[] = + { + {"debug", 'd', 0, G_OPTION_ARG_NONE, &opt_debug, "Enable debugging", NULL}, + {NULL}}; +#endif + +static GdkPixbuf *g_star_image = NULL; +static OsmGpsMapImage *g_last_image = NULL; + +static gboolean +on_button_press_event(GtkWidget *widget, GdkEventButton *event, gpointer user_data) +{ + OsmGpsMapPoint coord; + float lat, lon; + OsmGpsMap *map = OSM_GPS_MAP(widget); + OsmGpsMapTrack *othertrack = OSM_GPS_MAP_TRACK(user_data); + + int left_button = (event->button == 1) && (event->state == 0); + int middle_button = (event->button == 2) || ((event->button == 1) && (event->state & GDK_SHIFT_MASK)); + int right_button = (event->button == 3) || ((event->button == 1) && (event->state & GDK_CONTROL_MASK)); + + osm_gps_map_convert_screen_to_geographic(map, event->x, event->y, &coord); + osm_gps_map_point_get_degrees(&coord, &lat, &lon); + + if (event->type == GDK_3BUTTON_PRESS) + { + if (middle_button) + { + if (g_last_image) + osm_gps_map_image_remove(map, g_last_image); + } + if (right_button) + { + osm_gps_map_track_remove(map, othertrack); + } + } + else if (event->type == GDK_2BUTTON_PRESS) + { + if (left_button) + { + osm_gps_map_gps_add(map, + lat, + lon, + g_random_double_range(0, 360)); + } + if (middle_button) + { + g_last_image = osm_gps_map_image_add(map, + lat, + lon, + g_star_image); + } + if (right_button) + { + osm_gps_map_track_add_point(othertrack, &coord); + } + } + + return FALSE; +} + +static gboolean +on_map_changed_event(GtkWidget *widget, gpointer user_data) +{ + float lat, lon; + GtkEntry *entry = GTK_ENTRY(user_data); + OsmGpsMap *map = OSM_GPS_MAP(widget); + + g_object_get(map, "latitude", &lat, "longitude", &lon, NULL); + gchar *msg = g_strdup_printf("Map Centre: lattitude %f longitude %f", lat, lon); + gtk_entry_set_text(entry, msg); + g_free(msg); + + return FALSE; +} + +static gboolean +on_zoom_in_clicked_event(GtkWidget *widget, gpointer user_data) +{ + int zoom; + OsmGpsMap *map = OSM_GPS_MAP(user_data); + g_object_get(map, "zoom", &zoom, NULL); + osm_gps_map_set_zoom(map, zoom + 1); + return FALSE; +} + +static gboolean +on_zoom_out_clicked_event(GtkWidget *widget, gpointer user_data) +{ + int zoom; + OsmGpsMap *map = OSM_GPS_MAP(user_data); + g_object_get(map, "zoom", &zoom, NULL); + osm_gps_map_set_zoom(map, zoom - 1); + return FALSE; +} + +static gboolean +on_home_clicked_event(GtkWidget *widget, gpointer user_data) +{ + OsmGpsMap *map = OSM_GPS_MAP(user_data); + osm_gps_map_set_center_and_zoom(map, -43.5326, 172.6362, 12); + return FALSE; +} + +static gboolean +on_cache_clicked_event(GtkWidget *widget, gpointer user_data) +{ + OsmGpsMap *map = OSM_GPS_MAP(user_data); + if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) + { + int zoom, max_zoom; + OsmGpsMapPoint pt1, pt2; + osm_gps_map_get_bbox(map, &pt1, &pt2); + g_object_get(map, "zoom", &zoom, "max-zoom", &max_zoom, NULL); + osm_gps_map_download_maps(map, &pt1, &pt2, zoom, max_zoom); + } + else + { + osm_gps_map_download_cancel_all(map); + } + return FALSE; +} + +static void +on_tiles_queued_changed(OsmGpsMap *image, GParamSpec *pspec, gpointer user_data) +{ + gchar *s; + int tiles; + GtkLabel *label = GTK_LABEL(user_data); + g_object_get(image, "tiles-queued", &tiles, NULL); + s = g_strdup_printf("%d", tiles); + gtk_label_set_text(label, s); + g_free(s); +} + +static void +on_gps_alpha_changed(GtkAdjustment *adjustment, gpointer user_data) +{ + OsmGpsMap *map = OSM_GPS_MAP(user_data); + OsmGpsMapTrack *track = osm_gps_map_gps_get_track(map); + float f = gtk_adjustment_get_value(adjustment); + g_object_set(track, "alpha", f, NULL); +} + +static void +on_gps_width_changed(GtkAdjustment *adjustment, gpointer user_data) +{ + OsmGpsMap *map = OSM_GPS_MAP(user_data); + OsmGpsMapTrack *track = osm_gps_map_gps_get_track(map); + float f = gtk_adjustment_get_value(adjustment); + g_object_set(track, "line-width", f, NULL); +} + +static void +on_star_align_changed(GtkAdjustment *adjustment, gpointer user_data) +{ + const char *propname = user_data; + float f = gtk_adjustment_get_value(adjustment); + if (g_last_image) + g_object_set(g_last_image, propname, f, NULL); +} + +#if GTK_CHECK_VERSION(3, 4, 0) +static void +on_gps_color_changed(GtkColorChooser *widget, gpointer user_data) +{ + GdkRGBA c; + OsmGpsMapTrack *track = OSM_GPS_MAP_TRACK(user_data); + gtk_color_chooser_get_rgba(widget, &c); + osm_gps_map_track_set_color(track, &c); +} +#else +static void +on_gps_color_changed(GtkColorButton *widget, gpointer user_data) +{ + GdkRGBA c; + OsmGpsMapTrack *track = OSM_GPS_MAP_TRACK(user_data); + gtk_color_button_get_rgba(widget, &c); + osm_gps_map_track_set_color(track, &c); +} + +#endif + +static void +on_close(GtkWidget *widget, gpointer user_data) +{ + gtk_widget_destroy(widget); + gtk_main_quit(); +} + +static void +usage(GOptionContext *context) +{ + int i; + + puts(g_option_context_get_help(context, TRUE, NULL)); + + printf("Valid map sources:\n"); + for (i = OSM_GPS_MAP_SOURCE_NULL; i <= OSM_GPS_MAP_SOURCE_LAST; i++) + { + const char *name = osm_gps_map_source_get_friendly_name(i); + const char *uri = osm_gps_map_source_get_repo_uri(i); + if (uri != NULL) + printf("\t%d:\t%s\n", i, name); + } +} + +int main(int argc, char **argv) +{ + GtkBuilder *builder; + GtkWidget *widget; + GtkAccelGroup *ag; + OsmGpsMap *map; + OsmGpsMapLayer *osd; + OsmGpsMapTrack *rightclicktrack; + const char *repo_uri; + char *cachedir, *cachebasedir; + GError *error = NULL; + GOptionContext *context; + + gtk_init(&argc, &argv); + + context = g_option_context_new("- Map browser"); + g_option_context_set_help_enabled(context, FALSE); + g_option_context_add_main_entries(context, entries, NULL); +#if !GTK_CHECK_VERSION(3, 22, 0) + g_option_context_add_main_entries(context, debug_entries, NULL); +#endif + + if (!g_option_context_parse(context, &argc, &argv, &error)) + { + usage(context); + return 1; + } + + /* Only use the repo_uri to check if the user has supplied a + valid map source ID */ + repo_uri = osm_gps_map_source_get_repo_uri(opt_map_provider); + if (repo_uri == NULL) + { + usage(context); + return 2; + } + + cachebasedir = osm_gps_map_get_default_cache_directory(); + + if (opt_cache_base_dir && g_file_test(opt_cache_base_dir, G_FILE_TEST_IS_DIR)) + { + cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO); + cachebasedir = g_strdup(opt_cache_base_dir); + } + else if (opt_friendly_cache) + { + cachedir = g_strdup(OSM_GPS_MAP_CACHE_FRIENDLY); + } + else if (opt_no_cache) + { + cachedir = g_strdup(OSM_GPS_MAP_CACHE_DISABLED); + } + else + { + cachedir = g_strdup(OSM_GPS_MAP_CACHE_AUTO); + } + +#if !GTK_CHECK_VERSION(3, 22, 0) + // use --gtk-debug=updates on newer gtk + if (opt_debug) + gdk_window_set_debug_updates(TRUE); +#endif + + printf("Map Cache Dir: %s", cachedir); + printf("Map Provider: %s (%d)", osm_gps_map_source_get_friendly_name(opt_map_provider), opt_map_provider); + + map = g_object_new(OSM_TYPE_GPS_MAP, + "map-source", opt_map_provider, + "tile-cache", cachedir, + "tile-cache-base", cachebasedir, + "proxy-uri", g_getenv("http_proxy"), + "user-agent", "mapviewer.c", // Always set user-agent, for better tile-usage compliance + NULL); + + osd = g_object_new(OSM_TYPE_GPS_MAP_OSD, + "show-scale", TRUE, + "show-coordinates", TRUE, + "show-crosshair", TRUE, + "show-dpad", TRUE, + "show-zoom", TRUE, + "show-gps-in-dpad", TRUE, + "show-gps-in-zoom", FALSE, + "dpad-radius", 30, + NULL); + osm_gps_map_layer_add(OSM_GPS_MAP(map), osd); + g_object_unref(G_OBJECT(osd)); + + // Add a second track for right clicks + rightclicktrack = osm_gps_map_track_new(); + + if (opt_editable_tracks) + g_object_set(rightclicktrack, "editable", TRUE, NULL); + osm_gps_map_track_add(OSM_GPS_MAP(map), rightclicktrack); + + g_free(cachedir); + g_free(cachebasedir); + + // Enable keyboard navigation + osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_FULLSCREEN, GDK_KEY_F11); + osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_UP, GDK_KEY_Up); + osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_DOWN, GDK_KEY_Down); + osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_LEFT, GDK_KEY_Left); + osm_gps_map_set_keyboard_shortcut(map, OSM_GPS_MAP_KEY_RIGHT, GDK_KEY_Right); + + // Build the UI + g_star_image = gdk_pixbuf_new_from_file_at_size("poi.png", 24, 24, NULL); + + builder = gtk_builder_new(); + gtk_builder_add_from_file(builder, "mapviewer.ui", &error); + if (error) + g_error("ERROR: %s\n", error->message); + + gtk_box_pack_start( + GTK_BOX(gtk_builder_get_object(builder, "map_box")), + GTK_WIDGET(map), TRUE, TRUE, 0); + + // Init values + float lw, a; + GdkRGBA c; + OsmGpsMapTrack *gpstrack = osm_gps_map_gps_get_track(map); + g_object_get(gpstrack, "line-width", &lw, "alpha", &a, NULL); + osm_gps_map_track_get_color(gpstrack, &c); + gtk_adjustment_set_value( + GTK_ADJUSTMENT(gtk_builder_get_object(builder, "gps_width_adjustment")), + lw); + gtk_adjustment_set_value( + GTK_ADJUSTMENT(gtk_builder_get_object(builder, "gps_alpha_adjustment")), + a); + gtk_adjustment_set_value( + GTK_ADJUSTMENT(gtk_builder_get_object(builder, "star_xalign_adjustment")), + 0.5); + gtk_adjustment_set_value( + GTK_ADJUSTMENT(gtk_builder_get_object(builder, "star_yalign_adjustment")), + 0.5); +#if GTK_CHECK_VERSION(3, 4, 0) + gtk_color_chooser_set_rgba( + GTK_COLOR_CHOOSER(gtk_builder_get_object(builder, "gps_colorbutton")), + &c); +#else + gtk_color_button_set_rgba( + GTK_COLOR_BUTTON(gtk_builder_get_object(builder, "gps_colorbutton")), + &c); +#endif + + // Connect to signals + g_signal_connect( + gtk_builder_get_object(builder, "gps_colorbutton"), "color-set", + G_CALLBACK(on_gps_color_changed), (gpointer)gpstrack); + g_signal_connect( + gtk_builder_get_object(builder, "zoom_in_button"), "clicked", + G_CALLBACK(on_zoom_in_clicked_event), (gpointer)map); + g_signal_connect( + gtk_builder_get_object(builder, "zoom_out_button"), "clicked", + G_CALLBACK(on_zoom_out_clicked_event), (gpointer)map); + g_signal_connect( + gtk_builder_get_object(builder, "home_button"), "clicked", + G_CALLBACK(on_home_clicked_event), (gpointer)map); + g_signal_connect( + gtk_builder_get_object(builder, "cache_button"), "clicked", + G_CALLBACK(on_cache_clicked_event), (gpointer)map); + g_signal_connect( + gtk_builder_get_object(builder, "gps_alpha_adjustment"), "value-changed", + G_CALLBACK(on_gps_alpha_changed), (gpointer)map); + g_signal_connect( + gtk_builder_get_object(builder, "gps_width_adjustment"), "value-changed", + G_CALLBACK(on_gps_width_changed), (gpointer)map); + g_signal_connect( + gtk_builder_get_object(builder, "star_xalign_adjustment"), "value-changed", + G_CALLBACK(on_star_align_changed), (gpointer) "x-align"); + g_signal_connect( + gtk_builder_get_object(builder, "star_yalign_adjustment"), "value-changed", + G_CALLBACK(on_star_align_changed), (gpointer) "y-align"); + g_signal_connect(G_OBJECT(map), "button-press-event", + G_CALLBACK(on_button_press_event), (gpointer)rightclicktrack); + g_signal_connect(G_OBJECT(map), "changed", + G_CALLBACK(on_map_changed_event), + (gpointer)gtk_builder_get_object(builder, "text_entry")); + g_signal_connect(G_OBJECT(map), "notify::tiles-queued", + G_CALLBACK(on_tiles_queued_changed), + (gpointer)gtk_builder_get_object(builder, "cache_label")); + + widget = GTK_WIDGET(gtk_builder_get_object(builder, "window1")); + g_signal_connect(widget, "destroy", + G_CALLBACK(on_close), (gpointer)map); + // Setup accelerators. + ag = gtk_accel_group_new(); + gtk_accel_group_connect(ag, GDK_KEY_w, GDK_CONTROL_MASK, GTK_ACCEL_MASK, + g_cclosure_new(gtk_main_quit, NULL, NULL)); + gtk_accel_group_connect(ag, GDK_KEY_q, GDK_CONTROL_MASK, GTK_ACCEL_MASK, + g_cclosure_new(gtk_main_quit, NULL, NULL)); + gtk_window_add_accel_group(GTK_WINDOW(widget), ag); + + gtk_widget_show_all(widget); + + g_log_set_handler("OsmGpsMap", G_LOG_LEVEL_MASK, g_log_default_handler, NULL); + gtk_main(); + + return 0; +} diff --git a/test-examples/examples/mapviewer.js b/test-examples/examples/mapviewer.js new file mode 100755 index 0000000..71958b4 --- /dev/null +++ b/test-examples/examples/mapviewer.js @@ -0,0 +1,34 @@ +#!/usr/bin/seed + +// You probbably need to tell GObject introspection where to find the bindings +// export LD_LIBRARY_PATH=../src/.libs/ +// export GI_TYPELIB_PATH=../src/ + +const Gtk = imports.gi.Gtk; +const Osm = imports.gi.OsmGpsMap; + +Gtk.init(0, null); + +var win = new Gtk.Window({ type: Gtk.WindowType.TOPLEVEL }); +win.set_border_width(10); +win.set_default_size(400,400); + +// ARRRGGGHHHHH GNOME +if (0) + // GJS makes me do this + win.connect("delete-event", Gtk.main_quit); +else + // Seed makes me do this + win.signal.delete_event.connect(Gtk.main_quit); + +var map = new Osm.OsmGpsMap() +var osd = new Osm.Osd() + +map.layer_add(osd) +win.add(map); + +win.show_all(); + +Gtk.main(); + + diff --git a/test-examples/examples/mapviewer.py b/test-examples/examples/mapviewer.py new file mode 100755 index 0000000..5313edc --- /dev/null +++ b/test-examples/examples/mapviewer.py @@ -0,0 +1,299 @@ +#!/usr/bin/env python3 + +""" +Copyright (C) Hadley Rich 2008 +based on main.c - with thanks to John Stowers + +This is free software: you can redistribute it and/or modify it +under the terms of the GNU General Public License +as published by the Free Software Foundation; version 2. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY; without even the implied warranty of +MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +GNU General Public License for more details. + +You should have received a copy of the GNU General Public License +along with this program; if not, see . +""" + +import random +import gi + +gi.require_version("Gdk", "3.0") +gi.require_version("Gtk", "3.0") +gi.require_version("OsmGpsMap", "1.0") + +from gi.repository import ( + Gdk, + GdkPixbuf, + GLib, + GObject, + Gtk, + OsmGpsMap as osmgpsmap, +) # noqa + +print(f"using library: {osmgpsmap.__file__} (version {osmgpsmap._version})") + +assert osmgpsmap._version == "1.0" + +class DummyMapNoGpsPoint(osmgpsmap.Map): + def do_draw_gps_point(self, drawable): + pass + + +GObject.type_register(DummyMapNoGpsPoint) + + +class DummyLayer(GObject.GObject, osmgpsmap.MapLayer): + def __init__(self): + GObject.GObject.__init__(self) + + def do_draw(self, gpsmap, gdkdrawable): + pass + + def do_render(self, gpsmap): + pass + + def do_busy(self): + return False + + def do_button_press(self, gpsmap, gdkeventbutton): + return False + + +GObject.type_register(DummyLayer) + + +class UI(Gtk.Window): + def __init__(self): + Gtk.Window.__init__(self, type=Gtk.WindowType.TOPLEVEL) + + self.set_default_size(500, 500) + self.connect("destroy", lambda x: Gtk.main_quit()) + self.set_title("OpenStreetMap GPS Mapper") + + self.vbox = Gtk.VBox(homogeneous=False, spacing=0) + self.add(self.vbox) + + if 0: + self.osm = DummyMapNoGpsPoint() + else: + self.osm = osmgpsmap.Map() + self.osm.layer_add( + osmgpsmap.MapOsd(show_dpad=True, + show_zoom=True, + show_crosshair=True) + ) + self.osm.set_property("map-source", osmgpsmap.MapSource_t.OPENSTREETMAP) + self.osm.layer_add(DummyLayer()) + + self.last_image = None + + self.osm.connect("button_press_event", self.on_button_press) + self.osm.connect("changed", self.on_map_change) + + # connect keyboard shortcuts + self.osm.set_keyboard_shortcut( + osmgpsmap.MapKey_t.FULLSCREEN, Gdk.keyval_from_name("F11") + ) + self.osm.set_keyboard_shortcut( + osmgpsmap.MapKey_t.UP, Gdk.keyval_from_name("Up") + ) + self.osm.set_keyboard_shortcut( + osmgpsmap.MapKey_t.DOWN, Gdk.keyval_from_name("Down") + ) + self.osm.set_keyboard_shortcut( + osmgpsmap.MapKey_t.LEFT, Gdk.keyval_from_name("Left") + ) + self.osm.set_keyboard_shortcut( + osmgpsmap.MapKey_t.RIGHT, Gdk.keyval_from_name("Right") + ) + + # connect to tooltip + self.osm.props.has_tooltip = True + self.osm.connect("query-tooltip", self.on_query_tooltip) + + self.latlon_entry = Gtk.Entry() + + zoom_in_button = Gtk.Button.new_from_icon_name("zoom-in", + Gtk.IconSize.BUTTON) + zoom_in_button.connect("clicked", self.zoom_in_clicked) + zoom_out_button = Gtk.Button.new_from_icon_name("zoom-out", + Gtk.IconSize.BUTTON) + zoom_out_button.connect("clicked", self.zoom_out_clicked) + home_button = Gtk.Button.new_from_icon_name("go-home", + Gtk.IconSize.BUTTON) + home_button.connect("clicked", self.home_clicked) + cache_button = Gtk.Button(label="Cache") + cache_button.connect("clicked", self.cache_clicked) + + self.vbox.pack_start(self.osm, True, True, 0) + hbox = Gtk.HBox(homogeneous=False, spacing=0) + hbox.pack_start(zoom_in_button, False, True, 0) + hbox.pack_start(zoom_out_button, False, True, 0) + hbox.pack_start(home_button, False, True, 0) + hbox.pack_start(cache_button, False, True, 0) + + # add ability to test custom map URIs + ex = Gtk.Expander(label="Map Repository URI") + ex.props.use_markup = True + vb = Gtk.VBox() + self.repouri_entry = Gtk.Entry() + self.repouri_entry.set_text(self.osm.props.repo_uri) + self.image_format_entry = Gtk.Entry() + self.image_format_entry.set_text(self.osm.props.image_format) + + lbl = Gtk.Label( + label="""Enter an repository URL to fetch map tiles \ +from in the box below. Special metacharacters may be included in this url + +Metacharacters: +\t#X\tMax X location +\t#Y\tMax Y location +\t#Z\tMap zoom (0 = min zoom, fully zoomed out) +\t#S\tInverse zoom (max-zoom - #Z) +\t#Q\tQuadtree encoded tile (qrts) +\t#W\tQuadtree encoded tile (1234) +\t#U\tEncoding not implemeted +\t#R\tRandom integer, 0-4""" + ) + lbl.props.xalign = 0 + lbl.props.use_markup = True + lbl.props.wrap = True + + ex.add(vb) + vb.pack_start(lbl, False, True, 0) + + hb = Gtk.HBox() + hb.pack_start(Gtk.Label(label="URI: "), False, True, 0) + hb.pack_start(self.repouri_entry, True, True, 0) + vb.pack_start(hb, False, True, 0) + + hb = Gtk.HBox() + hb.pack_start(Gtk.Label(label="Image Format: "), False, True, 0) + hb.pack_start(self.image_format_entry, True, True, 0) + vb.pack_start(hb, False, True, 0) + + gobtn = Gtk.Button(label="Load Map URI") + gobtn.connect("clicked", self.load_map_clicked) + vb.pack_start(gobtn, False, True, 0) + + self.show_tooltips = False + cb = Gtk.CheckButton(label="Show Location in Tooltips") + cb.props.active = self.show_tooltips + cb.connect("toggled", self.on_show_tooltips_toggled) + self.vbox.pack_end(cb, False, True, 0) + + cb = Gtk.CheckButton(label="Disable Cache") + cb.props.active = False + cb.connect("toggled", self.disable_cache_toggled) + self.vbox.pack_end(cb, False, True, 0) + + self.vbox.pack_end(ex, False, True, 0) + self.vbox.pack_end(self.latlon_entry, False, True, 0) + self.vbox.pack_end(hbox, False, True, 0) + + GLib.timeout_add(500, self.print_tiles) + + def disable_cache_toggled(self, btn): + if btn.props.active: + self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_DISABLED + else: + self.osm.props.tile_cache = osmgpsmap.MAP_CACHE_AUTO + + def on_show_tooltips_toggled(self, btn): + self.show_tooltips = btn.props.active + + def load_map_clicked(self, button): + uri = self.repouri_entry.get_text() + format = self.image_format_entry.get_text() + if uri and format: + if self.osm: + # remove old map + self.vbox.remove(self.osm) + try: + self.osm = osmgpsmap.Map(repo_uri=uri, image_format=format) + except Exception as e: + print("ERROR:", e) + self.osm = osmgpsmap.Map() + + self.vbox.pack_start(self.osm, True, True, 0) + self.osm.show() + + def print_tiles(self): + if self.osm.props.tiles_queued != 0: + print(self.osm.props.tiles_queued, "tiles queued") + return True + + def zoom_in_clicked(self, button): + self.osm.set_zoom(self.osm.props.zoom + 1) + + def zoom_out_clicked(self, button): + self.osm.set_zoom(self.osm.props.zoom - 1) + + def home_clicked(self, button): + self.osm.set_center_and_zoom(-44.39, 171.25, 12) + + def on_query_tooltip(self, widget, x, y, keyboard_tip, tooltip, data=None): + if keyboard_tip: + return False + + if self.show_tooltips: + p = osmgpsmap.point_new_degrees(0.0, 0.0) + self.osm.convert_screen_to_geographic(x, y, p) + lat, lon = p.get_degrees() + tooltip.set_markup(f"{lat:+.4f}, {lon:+.4f}") + return True + + return False + + def cache_clicked(self, button): + bbox = self.osm.get_bbox() + self.osm.download_maps( + *bbox, + zoom_start=self.osm.props.zoom, + zoom_end=self.osm.props.max_zoom + ) + + def on_map_change(self, osm): + self.latlon_entry.set_text( + f"Map Centre: latitude {self.osm.props.latitude} " + f"longitude {self.osm.props.longitude}" + ) + + def on_button_press(self, osm, event): + state = event.get_state() + lat, lon = self.osm.get_event_location(event).get_degrees() + + left = event.button == 1 and state == 0 + middle = event.button == 2 or ( + event.button == 1 and state & Gdk.ModifierType.SHIFT_MASK + ) + right = event.button == 3 or ( + event.button == 1 and state & Gdk.ModifierType.CONTROL_MASK + ) + + # work around binding bug with invalid variable name + GDK_2BUTTON_PRESS = getattr(Gdk.EventType, "2BUTTON_PRESS") + GDK_3BUTTON_PRESS = getattr(Gdk.EventType, "3BUTTON_PRESS") + + if event.type == GDK_3BUTTON_PRESS: + if middle: + if self.last_image is not None: + self.osm.image_remove(self.last_image) + self.last_image = None + elif event.type == GDK_2BUTTON_PRESS: + if left: + self.osm.gps_add(lat, lon, heading=random.random() * 360) + if middle: + pb = GdkPixbuf.Pixbuf.new_from_file_at_size("poi.png", 24, 24) + self.last_image = self.osm.image_add(lat, lon, pb) + if right: + pass + + +if __name__ == "__main__": + u = UI() + u.show_all() + Gtk.main() diff --git a/test-examples/examples/poi.png b/test-examples/examples/poi.png new file mode 100644 index 0000000..4ab54c9 Binary files /dev/null and b/test-examples/examples/poi.png differ diff --git a/test-examples/examples/polygon.c b/test-examples/examples/polygon.c new file mode 100644 index 0000000..b8d1e89 --- /dev/null +++ b/test-examples/examples/polygon.c @@ -0,0 +1,47 @@ +#include +#include "osm-gps-map.h" + +int +main (int argc, + char *argv[]) +{ + OsmGpsMap *map; + OsmGpsMapPolygon* poly; + GtkWidget *window; + + gtk_init (&argc, &argv); + + window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + gtk_window_set_title (GTK_WINDOW (window), "Window"); + g_signal_connect (window, "destroy", G_CALLBACK (gtk_main_quit), NULL); + + + map = g_object_new (OSM_TYPE_GPS_MAP, NULL); + gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(map)); + + poly = osm_gps_map_polygon_new(); + OsmGpsMapTrack* polytrack = osm_gps_map_track_new(); + + OsmGpsMapPoint* p1, *p2, *p3; + p1 = osm_gps_map_point_new_radians(1.25663706, -0.488692191); + p2 = osm_gps_map_point_new_radians(1.06465084, -0.750491578); + p3 = osm_gps_map_point_new_radians(1.064650849, -0.191986218); + + osm_gps_map_track_add_point(polytrack, p1); + osm_gps_map_track_add_point(polytrack, p2); + osm_gps_map_track_add_point(polytrack, p3); + + g_object_set(poly, "track", polytrack, NULL); + g_object_set(poly, "editable", TRUE, NULL); + + osm_gps_map_polygon_add(map, poly); + + gtk_widget_show (GTK_WIDGET(map)); + gtk_widget_show (window); + + gtk_main (); + + return 0; +} + +