示例#1
0
void track::fromGarminText(char const* file){
	FILE* f = fopen(file, "r");
	char datebuff[32];
	if(f){
		fseek(f, 0, SEEK_END);
		long size = ftell(f);
		rewind(f);

		std::vector<char> buffer;
		buffer.resize(size+1);
		size = fread(&buffer[0], 1, size, f);
		fclose(f);
		buffer[size] = 0;

		const char* pos = strstr(&buffer[0], "trkpt\n");
		if(!pos)
			return;

		pos = lineskip(lineskip(pos));

		while(*pos){
			trkpoint temp;
			sscanf(pos, "%u %u %f %f %f %s", &temp.ID, &temp.trksegID, &temp.lat, &temp.lon, &temp.ele, datebuff);
			parse_date_and_time(datebuff, &temp.timestamp);
			pos = lineskip(pos);
			m_data.push_back(temp);
		}
	}
}
示例#2
0
static void
parse_track_waypoint(void)
{
    char *str;
    int column = -1;
    waypoint *wpt;

    bind_fields(trkpt_header);
    wpt = waypt_new();

    while ((str = csv_lineparse(NULL, "\t", "", column++))) {
        int field_no;
        double x;

        if (! *str) continue;

        field_no = header_fields[trkpt_header][column];
        switch(field_no) {
        case 1:
            parse_coordinates(str, datum_index, grid_index,
                              &wpt->latitude, &wpt->longitude, MYNAME);
            break;
        case 2:
            parse_date_and_time(str, &wpt->creation_time);
            break;
        case 3:
            if (parse_distance(str, &x, 1, MYNAME))
                wpt->altitude = x;
            break;
        case 4:
            if (parse_distance(str, &x, 1, MYNAME)) WAYPT_SET(wpt, depth, x);
            break;
        case 5:
            if (parse_temperature(str, &x)) WAYPT_SET(wpt, temperature, x);
            break;
        case 8:
            if (parse_speed(str, &x, 1, MYNAME)) WAYPT_SET(wpt, speed, x);
            break;
        case 9:
            WAYPT_SET(wpt, course, atoi(str));
            break;
        }
    }
    track_add_wpt(current_trk, wpt);
}
示例#3
0
static void
parse_waypoint(void)
{
    char *str;
    int column = -1;
    waypoint *wpt;
    garmin_fs_p gmsd = NULL;

    bind_fields(waypt_header);

    wpt = waypt_new();
    gmsd = garmin_fs_alloc(-1);
    fs_chain_add(&wpt->fs, (format_specific_data *) gmsd);

    while ((str = csv_lineparse(NULL, "\t", "", column++)))
    {
        int i, dynamic;
        double d;
        int field_no = header_fields[waypt_header][column];

        switch(field_no) {
        case  1:
            wpt->shortname = DUPSTR(str);
            break;
        case  2:
            wpt->notes = DUPSTR(str);
            break;
        case  3:
            for (i = 0; i <= gt_waypt_class_map_line; i++) {
                if (case_ignore_strcmp(str, gt_waypt_class_names[i]) == 0) {
                    GMSD_SET(wpt_class, i);
                    break;
                }
            }
            break;
        case  4:
            parse_coordinates(str, datum_index, grid_index,
                              &wpt->latitude, &wpt->longitude, MYNAME);
            break;
        case  5:
            if (parse_distance(str, &d, 1, MYNAME)) wpt->altitude = d;
            break;
        case  6:
            if (parse_distance(str, &d, 1, MYNAME)) WAYPT_SET(wpt, depth, d);
            break;
        case  7:
            if (parse_distance(str, &d, 1, MYNAME)) WAYPT_SET(wpt, proximity, d);
            break;
        case  8:
            if (parse_temperature(str, &d)) WAYPT_SET(wpt, temperature, d);
            break;
        case  9:
            if (parse_display(str, &i)) GMSD_SET(display, i);
            break;
        case 10:
            break;	/* skip color */
        case 11:
            i = gt_find_icon_number_from_desc(str, GDB);
            GMSD_SET(icon, i);
            wpt->icon_descr = gt_find_desc_from_icon_number(i, GDB, &dynamic);
            wpt->wpt_flags.icon_descr_is_dynamic = dynamic;
            break;
        case 12:
            GMSD_SETSTR(facility, str);
            break;
        case 13:
            GMSD_SETSTR(city, str);
            break;
        case 14:
            GMSD_SETSTR(state, str);
            break;
        case 15:
            GMSD_SETSTR(country, str);
            GMSD_SETSTR(cc, gt_get_icao_cc(str, wpt->shortname));
            break;
        case 16:
            parse_date_and_time(str, &wpt->creation_time);
            break;
        case 17:
            wpt->url = DUPSTR(str);
            break;
        case 18:
            GMSD_SET(category, parse_categories(str));
            break;
        default:
            break;
        }
    }
    waypt_add(wpt);
}