static void write_gpx_header(FILE *fp)
{
g_return_if_fail(fp);
- fprintf(fp,
+ g_fprintf(fp,
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
"<gpx version=\"1.0\"\n"
- "creator=\"convert2gpx.pl http://www.tangogps.org\"\n"
+ "creator=\"GPS tracker for Maemo\"\n"
"xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n"
"xmlns=\"http://www.topografix.com/GPX/1/0\"\n"
"xsi:schemaLocation=\"http://www.topografix.com/GPX/1/0 http://www.topografix.com/GPX/1/0/gpx.xsd\">\n"
static void write_gpx_footer(FILE *fp)
{
g_return_if_fail(fp);
- fprintf(fp, "</trkseg>\n</trk>\n</gpx>\n");
+ g_fprintf(fp, "</trkseg>\n</trk>\n</gpx>\n");
}
static void cb_start_stop (GtkWidget * w, AppData * data)
if (filename) {
if(g_file_test(data->intermediate_gpx_data_filename, G_FILE_TEST_IS_REGULAR | G_FILE_TEST_EXISTS)) {
g_rename(data->intermediate_gpx_data_filename, filename);
- g_print ("File saved as %s\n", filename);
+ //g_print ("File saved as %s\n", filename);
hildon_banner_show_information(GTK_WIDGET(data->window), NULL, filename);
}
else {
AppData *app_data = data;
GtkLabel *info = (GtkLabel*)app_data->status_label;
GString *msg;
+ FILE *fp = app_data->outf_p;
+ gchar sbuf1[G_ASCII_DTOSTR_BUF_SIZE], sbuf2[G_ASCII_DTOSTR_BUF_SIZE];
if (!device)
return;
msg = g_string_sized_new (512);
- if (device->fix) {
- if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
- g_print ("time = %f\n", device->fix->time);
- g_string_append_printf(msg, "time = %f\n", device->fix->time);
- }
+ if (device->fix && device->status) {
+ if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
+ //g_print ("lat = %f, long = %f\n", device->fix->latitude, device->fix->longitude);
+ g_string_append_printf (msg, "lat = %f, long = %f\n",
+ device->fix->latitude,
+ device->fix->longitude);
+ if(fp)
+ g_fprintf(fp, "\n<trkpt lat=\"%s\" lon=\"%s\">\n",
+ g_ascii_formatd(sbuf1, sizeof(sbuf1), "%f", device->fix->latitude),
+ g_ascii_formatd(sbuf2, sizeof(sbuf2), "%f", device->fix->longitude));
+
+ if (device->fix->fields & LOCATION_GPS_DEVICE_TIME_SET) {
+ //g_print ("time = %f\n", device->fix->time);
+ g_string_append_printf(msg, "time = %F\n", device->fix->time);
+ if(fp) {
+ gchar st[64];
+ struct tm *tmp;
+ time_t t = device->fix->time;
+ tmp = localtime(&t);
+ strftime(st, sizeof(st), "%FT%T%Z", tmp);
+ /* FIXME Is this really correct */
+ g_fprintf(fp, "<time>%s</time>\n", st);
+ }
+ }
- if (device->fix->fields & LOCATION_GPS_DEVICE_LATLONG_SET) {
- g_print ("lat = %f, long = %f\n",
- device->fix->latitude,
- device->fix->longitude);
- g_string_append_printf (msg, "lat = %f, long = %f\n",
- device->fix->latitude,
- device->fix->longitude);
- }
+ if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
+ //g_print ("alt = %f\n", device->fix->altitude);
+ g_string_append_printf (msg, "alt = %f\n", device->fix->altitude);
+ if(fp)
+ g_fprintf(fp, "<ele>%s</ele>\n", g_ascii_formatd(sbuf1, sizeof(sbuf1), "%f", device->fix->altitude));
- if (device->fix->fields & LOCATION_GPS_DEVICE_ALTITUDE_SET) {
- g_print ("alt = %f\n", device->fix->altitude);
- g_string_append_printf (msg, "alt = %f\n", device->fix->altitude);
- }
+ }
- if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
- g_print ("speed = %f\n", device->fix->speed);
- g_string_append_printf (msg, "speed = %f, ", device->fix->speed);
- }
+ if (device->fix->fields & LOCATION_GPS_DEVICE_SPEED_SET) {
+ //g_print ("speed = %f\n", device->fix->speed);
+ g_string_append_printf (msg, "speed = %f, ", device->fix->speed);
+ if(fp)
+ g_fprintf(fp, "<speed>%s</speed>\n", g_ascii_formatd(sbuf1, sizeof(sbuf1), "%f", device->fix->speed));
+ }
- if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
- g_print ("track = %f\n", device->fix->track);
- g_string_append_printf (msg, "track = %f, ", device->fix->track);
- }
+ if (device->fix->fields & LOCATION_GPS_DEVICE_TRACK_SET) {
+ //g_print ("track = %f\n", device->fix->track);
+ g_string_append_printf (msg, "track = %f, ", device->fix->track);
+ if(fp)
+ g_fprintf(fp, "<course>%s</course>\n", g_ascii_formatd(sbuf1, sizeof(sbuf1), "%f", device->fix->track));
+ }
- if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
- g_print ("climb = %f\n", device->fix->climb);
- g_string_append_printf (msg, "climb = %f\n", device->fix->climb);
- }
+ if (device->fix->fields & LOCATION_GPS_DEVICE_CLIMB_SET) {
+ //g_print ("climb = %f\n", device->fix->climb);
+ g_string_append_printf (msg, "climb = %f\n", device->fix->climb);
+ }
- g_print ("Accuracy values:\n");
- g_print ("\tept = %e, eph = %e, epv = %e, epd = %e, "
- "eps = %e, epc = %e\n",
- device->fix->ept,
- device->fix->eph,
- device->fix->epv,
- device->fix->epd,
- device->fix->eps,
- device->fix->epc);
- }
+ //g_print ("Accuracy values:\n");
+ //g_print ("\tept = %e, eph = %e, epv = %e, epd = %e, "
+ // "eps = %e, epc = %e\n",
+ // device->fix->ept,
+ // device->fix->eph,
+ // device->fix->epv,
+ // device->fix->epd,
+ // device->fix->eps,
+ // device->fix->epc);
+ if(fp)
+ g_fprintf(fp, "</trkpt>\n");
+ }
+ }
- g_print ("Satellites in view: %d\n", device->satellites_in_view);
- g_print ("Satellites in use: %d\n", device->satellites_in_use);
+ //g_print ("Satellites in view: %d\n", device->satellites_in_view);
+ //g_print ("Satellites in use: %d\n", device->satellites_in_use);
g_string_append_printf (msg, "Satellites = % 2d/% 2d\n", device->satellites_in_use, device->satellites_in_view);
- g_print ("GPS status: %d\n", device->status);
+ //g_print ("GPS status: %d\n", device->status);
g_string_append_printf (msg, "GPS status: %d\n", device->status);
hildon_gtk_window_set_progress_indicator(GTK_WINDOW(app_data->window), device->status == LOCATION_GPS_DEVICE_STATUS_NO_FIX);
- if (device->cell_info) {
- if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
- g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
+ //if (device->cell_info) {
+ // if (device->cell_info->flags & LOCATION_CELL_INFO_GSM_CELL_INFO_SET)
+ // g_print ("Mobile Coutry Code GSM: %d\n", device->cell_info->gsm_cell_info.mcc);
- if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
- g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
- }
+ // if (device->cell_info->flags & LOCATION_CELL_INFO_WCDMA_CELL_INFO_SET)
+ // g_print ("Mobile Coutry Code WCDMA: %d\n", device->cell_info->wcdma_cell_info.mcc);
+ //}
gtk_label_set_text(info, msg->str);
if(device->status != LOCATION_GPS_DEVICE_STATUS_NO_FIX)
if(data->outf_p)
fclose(data->outf_p);
g_unlink(data->intermediate_gpx_data_filename);
- g_object_unref (device);
- g_object_unref (control);
g_free(data->working_dir);
g_free(data->intermediate_gpx_data_filename);
g_free(data);
+ g_object_unref (device);
+ g_object_unref (control);
return 0;
}