#ifndef GPS_PROTOTYPES
#define GPS_PROTOTYPES

extern void Open_GPS_Uart1( void );
extern unsigned char PutcharTx1 ( unsigned char );
extern unsigned char PutstrTx1 ( const char * );
//extern void Transmit_GPS( void );
extern void Receive_GPS( void );
extern unsigned int Tx1BuffRoom( void );

typedef uint_4 uint32_t;
typedef sint_4 int32_t;
typedef sint_2 int16_t;
typedef uint_2 uint16_t;
typedef sint_1 int8_t;
typedef uint_1 uint8_t;

typedef struct
{
	uint32_t itow;	// GPS millisecond time of week 4
	int32_t frac;		// Nanosecond remainder of rounded ms 4
	int16_t week;		// GPS week 2
	uint8_t gpsfix;		// GPS fix type 1
	uint8_t flags;		// GPS flags 1
	int32_t x;					// ECEF X position 4 
	int32_t y;					// ECEF Y position 4
	int32_t z;					// ECEF Z position 4
	uint32_t pacc;		// 3D Position accuracy estimate 4
	int32_t vx;					// ECEF X velocity 4
	int32_t vy;					// ECEF Y velocity 4
	int32_t vz;					// ECEF Z velocity 4
	uint32_t sacc;		// Velocity accuracy estimate 4
	uint16_t pdop;	// Position dilution of position 2
	uint8_t res;		// Reserved 1
	uint8_t numsv;		// Number of sats used 1
	uint32_t res2;		// Reserved 2
	//double cpu_time;  //NOTE THIS IS NOT IN THE MESSAGE NORMALLY EXAMPLE
} NavSolMsg_Type;

typedef struct
{
    uint32_t itow;  // GPS Millisecond Time of Week
    uint32_t TAcc;  // Time Accuracy Estimate
    int32_t Nano;   // Nanoseconds of second, range -500000000 .. 500000000 (UTC)
    uint16_t Year;  // Year, range 1999..2099 (UTC)
    uint8_t Month;  // Month, range 1..12 (UTC)
    uint8_t Day;    // Day of Month, range 1..31 (UTC)
    uint8_t Hour;   // Hour of Day, range 0..23 (UTC) 
    uint8_t Min;    // Minute of Hour, range 0..59 (UTC)
    uint8_t Sec;    // Seconds of Minute, range 0..59 (UTC)
    uint8_t Valid;  //0x01 = Valid Time of Week 
                    //0x02 = Valid Week Number 
                    //0x04 = Valid UTC (Leap Seconds already known?)
} NavTimeUTC_Type;

typedef struct
{
	uint32_t itow;	// GPS millisecond time of week 4
	int32_t VelN;//North Velocity
	int32_t VelE;//East Velocity
	int32_t VelD;//Down Velocity
	uint32_t Speed;//Speed Magnitude
	uint32_t GSpeed;//Ground Speed
	int32_t Heading;//Heading scaled 1e-5 in deg
	uint32_t SpeedAcc;//Speed accuracy estimate
	uint32_t HeadinAcc;//Course Heading acc estimate
} NavVelNEDMsg_Type;

typedef struct
{
	uint32_t itow;	// GPS millisecond time of week 4
	int32_t Longitude;//1e-7 Longitude Degrees
	int32_t Latitude;//1e-7 Latitude Degrees
	int32_t Altitude;//Height above ellipsoid in mm
	int32_t AltitudeSea;//Height above mean sea level
	uint32_t HorzAcc;//Horizontal accuracy estimate
	uint32_t VertAcc;//vertical accuracy estimate
} NavPosLLHMsg_Type;

typedef struct
{
	uint32_t itow;	// GPS millisecond time of week 4
	int32_t Frac;//Frac Nano second remainder
	int16_t week;//week GPS week
	int8_t LeapS;//Leap second GPS-UTC
	uint8_t Valid;//Valid Flags: Time 0x01 Week# 0x02 Leap Sec 0x04
	uint32_t TAcc;//Time accuracy estimate Nano seconds
} NavTimeGPS_Type;

typedef struct
{
	uint32_t itow;	// GPS millisecond time of week 4
	int32_t Clkb;//Clk bias in nano seconds
	int32_t Clkd;//Clock drift in nano sec/sec
	uint32_t TAcc;//Time accuracy estimate nano seconds
	uint32_t FAcc;//Frequency Accuracy Estimate ps/s
} NavClockMsg_Type;

typedef struct
{
	uint32_t itow;	// GPS millisecond time of week 4
	uint8_t nchan;//Number of channels
	uint8_t res1; //reserved 1
	uint16_t res2; //reserved 2
} NavSVInfoMsg_Type;

typedef struct
{
        uint32_t itow; //ITOW  ms  GPS Millisecond Time of Week  
        int32_t ECEF_x; //ECEF_X  cm  ECEF X coordinate  
        int32_t ECEF_y; //ECEF_Y  cm  ECEF Y coordinate  
        int32_t ECEF_z; //ECEF_Z  cm  ECEF Z coordinate  
        uint32_t Pacc; //Pacc  cm  Position Accuracy Estimate  
} NavPosECEF_Type;

typedef struct
{
        uint32_t itow; //ITOW  ms  GPS Millisecond Time of Week  
        uint8_t GPSfix; //GPSfix  -  GPSfix Type, range 0..3 
                        //0x00 = no fix
                        //0x01 = dead reckoning only
                        //0x02 = 2D-fix
                        //0x03 = 3D-fix
                        //0x04 = GPS + dead reckoning combined
                        //0x05 = Time only fix
                        //0x06..0xff = reserved 

        uint8_t flags; //Flags  -  Navigation Status Flags 
                        //0x01 = GPSfixOK (i.e. within DOP and ACC Masks)
                        //0x02 = DiffSoln (is DGPS used)
                        //0x04 = WKNSET (is Week Number valid)
                        //0x08 = TOWSET (is Time of Week valid)
                        //0x?0 = reserved 
  
        uint8_t diffs; //DiffS  -  Differential Status 
                        //Bits [7,6] - reserved
                        //Bits [5,4] - reserved
                        //Bits [3,2] - reserved
                        //Bits [1:0] - DGPS Input Status
                        //00: none
                        //01: PR+PRR Correction
                        //10: PR+PRR+CP Correction
                        //11: High accuracy PR+PRR+CP Correction 

        uint8_t reserved; //res  -  Reserved  
        uint32_t ttff; //TTFF  -  Time to first fix (millisecond time tag)  
        uint32_t msss; //MSSS  -  Milliseconds since Startup / Reset  
} NavStatus_Type;

typedef struct
{
        uint32_t itow; //ITOW  ms  GPS Millisecond Time of Week  
        int32_t vel_ecef_x; //ECEFVX  cm/s  ECEF X velocity  
        int32_t vel_ecef_y; //ECEFVY  cm/s  ECEF Y velocity  
        int32_t vel_ecef_z; //ECEFVZ  cm/s  ECEF Z velocity  
        uint32_t sacc; //SAcc  cm/s  Speed Accuracy Estimate  
} NavVelECEF_Type;

#endif
