Example #1
0
static void
mmo_read_CObjIcons(mmo_data_t *data)
{
#ifdef MMO_DBG
	const char *sobj = "CObjIcons";
#endif
	int i;

	DBG((sobj, ":-----------------------------------------------------\n"));
	DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", 
		data->name, data->visible ? "yes" : "NO", data->objid));

	gbfseek(fin, 6, SEEK_CUR);	/* skip 6 unknown bytes */

	while ((i = gbfgetuint32(fin))) {
		char *name;
		(void) gbfgetuint32(fin);
		(void) gbfgetuint32(fin);
		name = mmo_readstr();
//		DBG((sobj, "bitmap(%d) = \"%s\"\n", i, name));
		mmo_register_icon(i, name);
		xfree(name);
		gbfseek(fin, gbfgetuint32(fin), SEEK_CUR);
	}
}
Example #2
0
static void
humminbird_read(void)
{
	while(! gbfeof(fin)) {
		gbuint32 signature;

		signature = gbfgetuint32(fin);

		switch(signature) {
			case WPT_MAGIC:
				humminbird_read_wpt(fin);
				break;
			case RTE_MAGIC:
				humminbird_read_route(fin);
				break;
			case TRK_MAGIC:
				humminbird_read_track(fin);
				return; /* Don't continue. The rest of the file is all zeores */
			case TRK_MAGIC2:
				humminbird_read_track_old(fin);
				return; /* Don't continue. The rest of the file is all zeores */
			default:
				fatal(MYNAME ": Invalid record header \"0x%08X\" (no or unknown humminbird file)!\n", signature);
		}
	}
}
Example #3
0
static mmo_data_t *
mmo_read_object(const waypoint *add)
{
	int objid;
	mmo_data_t *data = NULL;

	objid = gbfgetuint16(fin);
	if (objid == 0xFFFF) {
		gbuint16 version;
		char *sobj;
		int len;
		
		objid = mmo_object_id++;

		version = gbfgetuint16(fin);
		is_fatal(version != mmo_version, MYNAME ": Invalid version identifier!\n");
		
		len = gbfgetint16(fin);
		
		sobj = xmalloc(len + 1);
		sobj[len] = '\0';
		gbfread(sobj, len, 1, fin);
		
		if (strcmp(sobj, "CObjIcons") == 0) ico_object_id = objid;
		else if (strcmp(sobj, "CCategory") == 0) cat_object_id = objid;
		else if (strcmp(sobj, "CObjWaypoint") == 0) wpt_object_id = objid;
		else if (strcmp(sobj, "CObjRoute") == 0) rte_object_id = objid;
		else if (strcmp(sobj, "CObjTrack") == 0) trk_object_id = objid;
		else if (strcmp(sobj, "CObjCurrentPosition") == 0) pos_object_id = objid;
		else if (strcmp(sobj, "CObjText") == 0) txt_object_id = objid;
		else
			fatal(MYNAME ": Unknown Object \"%s\"!\n", sobj);
		xfree(sobj);
	}

	if (objid & 0x8000) {

		data = mmo_register_object(mmo_object_id++, NULL, 0);
		data->name = mmo_readstr();

		if (objid != cat_object_id) {
			data->ctime = gbfgetuint32(fin);
			data->mtime = gbfgetuint32(fin);
			data->locked = gbfgetc(fin);
			data->visible = gbfgetc(fin);
			(void) gbfgetuint16(fin);
			(void) gbfgetuint16(fin);
		
			if (objid != ico_object_id) mmo_read_category(data);
		}

		if (objid == cat_object_id) ; 	/* do nothing */		
		else if (objid == ico_object_id) mmo_read_CObjIcons(data);
		else if (objid == trk_object_id) {
			data->type = trkdata;
			mmo_read_CObjTrack(data);
		}
		else if (objid == wpt_object_id) {
			data->type = wptdata;
			mmo_read_CObjWaypoint(data);
		}
		else if (objid == rte_object_id) {
			data->type = rtedata;
			mmo_read_CObjRoute(data, add);
		}
		else if (objid == pos_object_id) mmo_read_CObjCurrentPosition(data);
		else if (objid == txt_object_id) mmo_read_CObjText(data);
		else
			fatal(MYNAME ": Unregistered Object-ID 0x%04X\n", objid);
	}
	else data = mmo_get_object(objid);
	
	return data;
}
Example #4
0
static void
mmo_read_CObjTrack(mmo_data_t *data)
{
#ifdef MMO_DBG
	const char *sobj = "CObjTrack";
#endif
	int tp, ctp;
	route_head *trk;

	DBG((sobj, ":-----------------------------------------------------\n"));
	DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", 
		data->name, data->visible ? "yes" : "NO", data->objid));

	trk = route_head_alloc();
	trk->rte_name = xstrdup(data->name);
	track_add_head(trk);

	tp = gbfgetint16(fin);
	DBG((sobj, "track has %d point(s)\n", tp));

	for (ctp = 0; ctp < tp; ctp++) {
		waypoint *wpt;
		char unk;
		
		wpt = waypt_new();
		
		wpt->latitude = gbfgetdbl(fin);
		wpt->longitude = gbfgetdbl(fin);
		unk = gbfgetc(fin);
		
		wpt->creation_time = gbfgetint32(fin);
		wpt->altitude = gbfgetflt(fin);

		if (unk != 0) {
			gbuint16 ux;
			ux = gbfgetuint16(fin);
			DBG((sobj, "u16 = %04X (%d)\n", ux, ux));
			if (unk > 1) {
				gbuint16 ux;
				ux = gbfgetuint16(fin);
				DBG((sobj, "u16 = %04X (%d)\n", ux, ux));
			}
		}
		track_add_wpt(trk, wpt);
	}
	
	if (mmo_version > 0) {
		gbuint32 u32;
		
		u32 = gbfgetuint32(fin); 	/* Min. update interval */
		DBG((sobj, "min. update interval = %d\n", u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
//		DBG((sobj, "unknown value = 0x%8X (%d)\n", u32, u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
//		DBG((sobj, "unknown value = 0x%8X (%d)\n", u32, u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
		DBG((sobj, "min. update distance = %d\n", u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
		DBG((sobj, "track partition interval = %d\n", u32 / 60));
		u32 = gbfgetuint32(fin); 	/* unknown */
//		DBG((sobj, "unknown value = 0x%8X (%d)\n", u32, u32));
		u32 = gbfgetuint32(fin); 	/* unknown */
		DBG((sobj, "tick interval = %d\n", u32 / 60));
		trk->line_color.bbggrr = gbfgetuint32(fin); 	/* rgb color */
		trk->line_color.opacity = 255;
		DBG((sobj, "color = 0x%06X\n", trk->line_color.bbggrr));
	}

	if (mmo_version >= 0x12) {
		char u8;
		
		u8 = gbfgetc(fin);
		DBG((sobj, "line width = %d - (since 0x12)\n", u8));
		u8 = gbfgetc(fin);
		DBG((sobj, "line style = %d - (since 0x12)\n", u8));
		u8 = gbfgetc(fin);
		DBG((sobj, "transparency = %d - (since 0x12)\n", u8));
		trk->line_color.opacity = 255 - (u8 * 51);

		if (mmo_version >= 0x16) {
			char u8;
			gbuint16 u16;
			
			u8 = gbfgetc(fin);
//			DBG((sobj, "u8 = 0x%X (since 0x16)\n", u8));
			u16 = gbfgetuint16(fin);
//			DBG((sobj, "u16 = 0x%X (since 0x16)\n", u16));
			u16 = gbfgetuint16(fin);
//			DBG((sobj, "u16 = 0x%X (since 0x16)\n", u16));
		}
	}
	
	if (trk->rte_waypt_ct == 0) {
		track_del_head(trk);
		data->data = NULL;
	}
}
Example #5
0
static void
mmo_read_CObjWaypoint(mmo_data_t *data)
{
#ifdef MMO_DBG
	const char *sobj = "CObjWaypoint";
#endif
	waypoint *wpt;
	time_t time;
	int rtelinks;
	mmo_data_t **rtelink = NULL;
	char *str;
	char buf[16];
	int i, ux;
	
	DBG((sobj, ":-----------------------------------------------------\n"));
	DBG((sobj, "name = \"%s\" [ visible=%s, id=0x%04X ]\n", 
		data->name, data->visible ? "yes" : "NO", data->objid));

	wpt = waypt_new();
	wpt->shortname = xstrdup(data->name);

	time = data->mtime;
	if (! time) time = data->ctime;
	if (time > 0) wpt->creation_time = time;

	wpt->latitude = gbfgetdbl(fin);
	wpt->longitude = gbfgetdbl(fin);

	DBG((sobj, "coordinates = %f / %f\n", wpt->latitude, wpt->longitude));

	rtelinks = gbfgetuint16(fin);
	if (rtelinks > 0) {

		rtelink = xcalloc(sizeof(*rtelink), rtelinks);
		DBG((sobj, "rtelinks = %d\n", rtelinks));

		for (i = 0; i < rtelinks; i++) {
			mmo_data_t *tmp;
			int objid;			

			DBG((sobj, "read rtelink number %d\n", i + 1));

			objid = gbfgetuint16(fin);
			gbfseek(fin, -2, SEEK_CUR);

			rtelink[i] = tmp = mmo_read_object(wpt);
			
			if ((objid < 0x8000) && (tmp != NULL) && (tmp->type == rtedata)) {
				route_head *rte = tmp->data;

				tmp->left--;
				route_add_wpt(rte, waypt_dupe(wpt));

				DBG((sobj, "\"%s\" Added to route \"%s\"\n", wpt->shortname, rte->rte_name));
			}
		}

	}
	
	str = mmo_readstr();	/* descr + url */
	if (strncmp(str, "_FILE_ ", 7) == 0) {
		char *cx, *cend;
		
		cx = lrtrim(str + 7);
		cend = strchr(cx, '\n');
		if (cend == NULL) cend = cx + strlen(cx);
		
		cx = lrtrim(xstrndup(cx, cend - cx));
		if (*cx) wpt->url = cx;
		else xfree(cx);

		if (*cend++) wpt->notes = xstrdup(cend);
		
		if (wpt->url) DBG((sobj, "url = \"%s\"\n", wpt->url));
	}
	else
		if (*str) wpt->notes = xstrdup(str);
	xfree(str);

	if (wpt->notes) DBG((sobj, "notes = \"%s\"\n", wpt->notes));

	mmo_fillbuf(buf, 12, 1);
	i = le_read32(&buf[8]);		/* icon */
	if (i != -1) {
		char key[16];
		char *name;
		
		snprintf(key, sizeof(key), "%d", i);
		if (avltree_find(icons, key, (void *)&name)) {
			wpt->icon_descr = xstrdup(name);
			wpt->wpt_flags.icon_descr_is_dynamic = 1;
			DBG((sobj, "icon = \"%s\"\n", wpt->icon_descr));
		}
	}

	wpt->proximity = le_read_float(&buf[4]);
	if (wpt->proximity) {
		wpt->wpt_flags.proximity = 1;
		DBG((sobj, "proximity = %f\n", wpt->proximity));
	}

	str = mmo_readstr();	/* name on gps ??? option ??? */
	if (*str) {
		wpt->description = wpt->shortname;
		wpt->shortname = str;
		DBG((sobj, "name on gps = %s\n", str));
	}
	else xfree(str);

	ux = gbfgetuint32(fin);
	DBG((sobj, "proximity type = %d\n", ux));

	if (rtelinks) {
		int i;

		for (i = 0; i < rtelinks; i++) {
			int j;
			route_head *rte = rtelink[i]->data;

			for (j = 0; j < rtelinks; j++) {
				if ((i != j) && (rtelink[i] == rtelink[j])) {
					rtelink[i]->loop = 1;
					break;
				}
			}
			rtelink[i]->done++;
			if ((rtelink[i]->left == 0) && (rtelink[i]->done == rte->rte_waypt_ct)) {
				if (mmo_version <= 0x11) mmo_end_of_route(rtelink[i]);
			}
		}
	}

	if (rtelink) {
		xfree(rtelink);
		waypt_free(wpt);
		data->data = NULL;
	}
	else waypt_add(wpt);
}
Example #6
0
static void
format_garmin_xt_proc_atrk(void)
{
	gbuint16	block=0, uu=0;
	gbuint32	Lat=0, Lon=0;
	gbuint32	Tim=0;
	double		LatF = 0, LonF = 0, AltF = 0;
	waypoint	*wpt;
	int		method = 0;
	unsigned char 	buf[3];
	gbint32 	num_trackpoints;

	// get the option for the processing the track name
	if ( opt_trk_header )
	{
		method = atoi(opt_trk_header);
	}

	if (! track) {
		track = route_head_alloc();
		// header option was not set to ignore
		if ( method !=1 )
		{
			track->rte_name = xstrdup("ATRK XT");
		}
		track_add_head(track);
	}

	// We think the word at offset 0xc is the trackpoint count.
	gbfseek(fin, 12, SEEK_SET);
	num_trackpoints = gbfgetuint32(fin);
	
	while (num_trackpoints--) {
		block = gbfgetuint16(fin);
		if (block != 0x0c)
			break;
			
		gbfread(&buf, 3, DATABLOCKSIZE, fin); //1. Lat
		Lat = buf[0] | (buf[1] << 8) | (buf[2] << 16);
		gbfread(&buf, 3, DATABLOCKSIZE, fin); //2. Lon
		Lon = buf[0] | (buf[1] << 8) | (buf[2] << 16);

		uu = gbfgetuint16(fin);
		Tim = gbfgetuint32(fin);

		Tim += 631065600; // adjustment to UnixTime
		LatF = Lat;
		if (LatF>8388608) {LatF -= 16777216;};
		LonF = Lon;
		if (LonF>8388608) {LonF -= 16777216;};
		AltF = (double)uu * GARMIN_XT_ELE - 1500;

		//create new waypoint
		wpt = waypt_new();

		//populate wpt;
		wpt->latitude = LatF*180/16777216;	/* Degrees */
		wpt->longitude = LonF*360/16777216; 	/* Degrees */
		wpt->altitude = AltF; 			/* Meters. */
		wpt->creation_time = Tim;  		/* Unix Time adjusted to Garmin time */

		track_add_wpt(track, wpt);
	}
}