UKHAS Wiki

UK High Altitude Society

User Tools

Site Tools


code:interrupt_driven_tsip

This is an old revision of the document!


#include "main.h"
//global(s)
extern gps_type Gps;
 
// Interrupt driven TSIP (lassen iq) parser for Atmel AVR
 
ISR(USART_RX_vect)			//UART interrupt on mega xx8 series
{
	static u08 LLA;
	static u08 VENU;
	static u08 placemark;
	static gps_type gps;
	char c=UDR0;
	char *d;
	placemarker++;
	if(c==0x03)			//end of a packet ie a new one is coming
	{
		placemarker=0;
		LLA=FALSE;
		VENU=FALSE;		//we dont know what sort of packet it is yet
	}
	else if(placemarker==2)		//packet id
	{
		switch(c)
		{
			case 0x4A:
				LLA=TRUE;
			break;
			case 0x56:
				VENU=TRUE;
			break;
			default:	//unknown packet, leave it
		}
	}
	if(LLA)
	{
		switch(placemarker)
		{
			case 3:
			d=&gps.latitude;
			break;
			case 7:
			d=&gps.longitude;
			break;
			case 11:
			d=&gps.altitude;
			break;
			default:
		}		
		if(d==&gps.latitude)
		{
			memcpy(d+placemarker-3,&c,1);
		}
		if(d==&gps.longitude)
		{
			memcpy(d+placemarker-7,&c,1);
		}
		if(d==&gps.latitude)
		{
			memcpy(d+placemarker-11,&c,1);
		}
		if(placemarker==14)
		{
			LLA=FALSE;
		}
	}
	if(VENU)
	{
		switch(placemarker)
		{
			case 3:
			d=&gps.veast;
			break;
			case 7:
			d=&gps.vnorth;
			break;
			case 11:
			d=&gps.vup;
			break;
			default:
		}		
		if(d==&gps.veast)
		{
			memcpy(d+placemarker-3,&c,1);
		}
		if(d==&gps.vnorth)
		{
			memcpy(d+placemarker-7,&c,1);
		}
		if(d==&gps.vup)
		{
			memcpy(d+placemarker-11,&c,1);
		}
		if(placemarker==14)
		{
			toggle_pin;		//toggles pin D5 - flashing LED tells us gps is working
			if(!Gps.packetflag)	//main has unlocked the data
			{
				Gps.packetflag=TRUE;	//this is usually the last interesting part of the fix info to come through
				Gps=gps;		//copy into the global variable
				VENU=FALSE;		//dont need to run again
			}
		}
	}
}
code/interrupt_driven_tsip.1213576353.txt.gz · Last modified: 2008/07/19 23:31 (external edit)

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki