Exemplo n.º 1
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);
		}
	}
}
Exemplo n.º 2
0
static void
nav_read(void)
{
	int len;
	char buf[MY_CBUF];
	
	while ((len = gbfread(buf, 1, sizeof(buf), fin))) {
		if (!XML_Parse(psr, buf, len, gbfeof(fin))) {
			fatal(MYNAME ":Parse error at %d: %s\n", 
				(int) XML_GetCurrentLineNumber(psr),
				XML_ErrorString(XML_GetErrorCode(psr)));
		}
	}

	XML_ParserFree(psr);
}
Exemplo n.º 3
0
static void
mmo_read(void)
{
#ifdef MMO_DBG
	const char *sobj = "main";
#endif
	gbfile *fx;
	int i;

	/* copy file to memory stream (needed for seek-ops and piped commands) */

	DBG(("main", "loading file \"%s\".\n", fin->name));
	
	fx = gbfopen(NULL, "wb", MYNAME);
	gbfcopyfrom(fx, fin, 0x7FFFFFFF);
	gbfrewind(fx);
	gbfclose(fin);
	fin = fx;
		
	mmo_obj_ct = gbfgetuint16(fin);
	DBG((sobj, "number of objects = %d\n", mmo_obj_ct));
	
	i = gbfgetuint16(fin);
	if (i != 0xFFFF) fatal(MYNAME ": Marker not equel to 0xFFFF!\n");

	mmo_version = gbfgetuint16(fin);
	DBG((sobj, "version = 0x%02X\n", mmo_version));

	mmo_filemark = 0xFFFF0000UL | be_read16(&mmo_version);
	DBG((sobj, "filemark = 0x%08X\n", mmo_filemark));

	gbfseek(fin, -4, SEEK_CUR);

	while (! gbfeof(fin)) {		/* main read loop */

		(void) mmo_read_object(NULL);

	}

#ifdef MMO_DBG
	printf("\n" MYNAME ":---------------------------------------\n");
	printf(MYNAME ": EOF reached, nice!!!\n");
	printf(MYNAME ": =======================================\n\n");
#endif	
}
Exemplo n.º 4
0
/*
 * Main Function to process Saved tracks file
 */
static void
format_garmin_xt_proc_strk(void)
{
	int 		Count = 0; // Used to obtain number of read bytes
	int		NumberOfTracks = 0, TracksCompleted = 0; // Number of tracks in the file and number of processed tracks
	gbuint16	trackbytes = 0; // Bytes in track
	gbuint8	TrackBlock[STRK_BLOCK_SIZE]; // File Block
	gbuint8 	ii; // temp variable
	double		Lat = 0, Lon = 0; // wpt data
	double		PrevLat = 0, PrevLon = 0, PrevEle = 0; // wpt data
	gbuint32	Time = 0, PrevTime =0; // wpt data
	int		FirstCoo;
	gbuint8	trk_color = 0xff;

	// Skip 12 bytes from the BOF
	gbfseek(fin, 12, SEEK_SET);

	// read # of tracks
	NumberOfTracks = gbfgetuint16(fin);

	// Skip 2 bytes
	gbfseek(fin, 2, SEEK_CUR);

	// Process all tracks one by one
	while ((TracksCompleted < NumberOfTracks) && (!gbfeof( fin ) ) )
	{
		route_head *tmp_track;
		waypoint	*wpt;
		char	*trk_name;
		trk_name = xmalloc(30);

		// Generate Track Header
		trackbytes = format_garmin_xt_rd_st_attrs(trk_name, &trk_color) - 50;

		tmp_track = route_head_alloc();
		// update track color
		tmp_track->line_color.bbggrr = colors[trk_color];
		tmp_track->line_color.opacity = 255;
		// update track name
		tmp_track->rte_name = trk_name;
		track_add_head(tmp_track);

		// This is the 1st coordinate of the track
		FirstCoo = TRUE;
		while (trackbytes>0)
		{
			if (trackbytes>=STRK_BLOCK_SIZE)
			{
				Count = gbfread(&TrackBlock, DATABLOCKSIZE, STRK_BLOCK_SIZE, fin);
				trackbytes -= STRK_BLOCK_SIZE;
			}
			else
			{
				Count = gbfread(&TrackBlock, DATABLOCKSIZE, trackbytes, fin);
				trackbytes = 0;
			}

			// decrypt loaded track block (Count - size of loaded TrackBlock)
			format_garmin_xt_decrypt_trk_blk(Count, TrackBlock);

			// process each track point in the loaded TrackBlock
			for (ii=1; ii <= ((Count-1) / 12); ii++)
			{
				// decompose loaded track block part (track point)
				format_garmin_xt_decomp_trk_blk(ii, TrackBlock, &PrevEle, &Lat, &Lon, &Time);

				// Add point to the track if not the first point
				if (!FirstCoo)
				{
					//create new waypoint
					wpt = waypt_new();

					//populate wpt;
					wpt->latitude = PrevLat;	/* Degrees */
					wpt->longitude = PrevLon; 	/* Degrees */
					wpt->altitude = PrevEle; 			/* Meters. */
					wpt->creation_time = Time;  		/* Unix Time adjusted to Garmin time */

					// add way point to the track
					track_add_wpt(tmp_track, wpt);
				}
				else
				{
					FirstCoo = FALSE;
				}	
				PrevLat = Lat;
				PrevLon = Lon;
				PrevTime = Time;
			}
		}

		// decompose elevation for the last point
		if (Count > 12)
		{
			Count--;
		}
		format_garmin_xt_decomp_last_ele(Count, &PrevEle, TrackBlock);

		//create new waypoint
		wpt = waypt_new();

		//populate wpt;
		wpt->latitude = PrevLat;	/* Degrees */
		wpt->longitude = PrevLon; 	/* Degrees */
		wpt->altitude = PrevEle; 			/* Meters. */
		wpt->creation_time = Time;  		/* Unix Time adjusted to Garmin time */

		// add way point to the track
		track_add_wpt(tmp_track, wpt);

		// update completed tracks counter
		TracksCompleted++;
	}
}