void location_add(/*@unused@*/ Widget w, XtPointer clientData, /*@unused@*/ XtPointer callData) { char name[100]; char s_long[20]; char s_lat[20]; FILE *f, *fout; char temp[200]; char *temp_ptr; Widget my_text = (Widget) clientData; int len,n,found; char location_file_path[MAX_VALUE]; char location_db_path[MAX_VALUE]; get_user_base_dir("config/locations.sys", location_file_path, sizeof(location_file_path)); get_user_base_dir("data/locations_db.dat", location_db_path, sizeof(location_db_path)); temp_ptr = XmTextFieldGetString(my_text); xastir_snprintf(name, sizeof(name), "%s", temp_ptr); XtFree(temp_ptr); (void)remove_trailing_spaces(name); XmTextFieldSetString(my_text,""); /* should check for name used already */ found=0; f=fopen(location_file_path,"r"); if (f!=NULL) { while (!feof(f) && !found) { (void)get_line(f,temp,200); if (!feof(f) && strlen(temp)>8) { temp_ptr=strtok(temp,"|"); /* get the name */ if (temp_ptr!=NULL) { if (strcmp(name,temp)==0) found=1; } } } (void)fclose(f); } else fprintf(stderr,"Couldn't open file: %s\n", location_file_path ); if (!found) { /* delete entire list available */ XmListDeleteAllItems(location_list); len = (int)strlen(name); if (len>0 && len<100){ fout = fopen(location_file_path,"a"); if (fout!=NULL) { convert_lat_l2s(center_latitude, s_lat, sizeof(s_lat), CONVERT_HP_NOSP); convert_lon_l2s(center_longitude, s_long, sizeof(s_long), CONVERT_HP_NOSP); fprintf(fout,"%s|%s %s %ld\n",name,s_lat,s_long,scale_y); (void)fclose(fout); } else fprintf(stderr,"Couldn't open file: %s\n", location_file_path ); } else popup_message_always(langcode("POPEM00022"),langcode("POPEM00023")); /* resort the list and put it back up */ n=1; clear_sort_file(location_db_path); jump_sort(); sort_list(location_db_path,200,location_list,&n); } else popup_message_always(langcode("POPEM00022"),langcode("POPEM00024")); /* dupe name */ }
// Function which will send an NMEA sentence to a Garmin GPS which // will create a waypoint if the Garmin is set to NMEA-in/NMEA-out // mode. The sentence looks like this: // // $GPWPL,4807.038,N,01131.000,E,WPTNME*31 // // $GPWPL,4849.65,N,06428.53,W,0001*54 // $GPWPL,4849.70,N,06428.50,W,0002*50 // // 4807.038,N Latitude // 01131.000,E Longitude // WPTNME Waypoint Name (stick to 6 chars for compatibility?) // *31 Checksum, always begins with '*' // // // Future implementation ideas: // // Create linked list of waypoints/location. // Use the list to prevent multiple writes of the same waypoint if // nothing has changed. // // Use the list to check distance of previously-written waypoints. // If we're out of range, delete the waypoint and remove it from the // list. // // Perhaps write the list to disk also. As we shut down, delete the // waypoints (self-cleaning). As we come up, load them in again? // We could also just continue cleaning out waypoints that are // out-of-range since the last time we ran the program. That's // probably a better solution. // void create_garmin_waypoint(long latitude,long longitude,char *call_sign) { char short_callsign[10]; char lat_string[15]; char long_string[15]; char lat_char; char long_char; int i,j,len; char out_string[80]; char out_string2[80]; convert_lat_l2s(latitude, lat_string, sizeof(lat_string), CONVERT_HP_NOSP); lat_char = lat_string[strlen(lat_string) - 1]; lat_string[strlen(lat_string) - 1] = '\0'; convert_lon_l2s(longitude, long_string, sizeof(long_string), CONVERT_HP_NOSP); long_char = long_string[strlen(long_string) - 1]; long_string[strlen(long_string) - 1] = '\0'; len = strlen(call_sign); if (len > 9) len = 9; j = 0; for (i = 0; i <= len; i++) { // Copy the '\0' as well if (call_sign[i] != '-') { // We don't want the dash short_callsign[j++] = call_sign[i]; } } short_callsign[6] = '\0'; // Truncate at 6 chars // Convert to upper case. Garmin's don't seem to like lower // case waypoint names to_upper(short_callsign); //fprintf(stderr,"Creating waypoint for %s:%s\n",call_sign,short_callsign); xastir_snprintf(out_string, sizeof(out_string), "$GPWPL,%s,%c,%s,%c,%s*", lat_string, lat_char, long_string, long_char, short_callsign); nmea_checksum(out_string); xastir_snprintf(out_string2, sizeof(out_string2), "%s%s", out_string, checksum); output_waypoint_data(out_string2); //fprintf(stderr,"%s\n",out_string2); }