// UBLOX GPS header info


#define GPS_PI 	(3.1415926535898)
#define	D2R		(GPS_PI/180.0)
#define	R2D		(180.0/GPS_PI)
#define WEEK 	(604800.)
#define MAXCHAN  (8)


#define MAX_RPTBUF (256)


/* UBLOX packets have the following structure, whether report or command. */
typedef struct {
	unsigned char
		sync1,				//0xB5
		sync2,				//0x62
		classID,			// message class
		msgID,				//message ID
		len_LOB,				//low order byte of len (do we really need more than 256?)
		len_HOB;				//high order byte on len (always 0?)
	unsigned char
		buf[MAX_RPTBUF];	//report str with checksom
} UBXPKT;


typedef struct {
	unsigned char
		chn,				//channel number
		svid,				//0x62
		sv_flags,			// 
		quality,				
		cno,				
		elev;				
	short azim;
	long prRes;
} SVdata;

//UBX Class Ids : updated with prefix of UBLOX_ : see UBX Protocol
#define UBX_NAV 0x01  // Navigation results
#define UBX_RXM 0x02  // Receiver Manager Mexxages nov08 ..not used
#define UBX_INF 0x04  // Information messages: nov08 ..not used
#define UBX_ACK 0x05  // Ack/Nack messages, replies to CFG messages
#define UBX_CFG 0x06  // Configuration input messages
#define UBX_MON 0x0A  // Monitoring messages: nov08 ..not used
#define UBX_AID 0x0B  // AssistNow AID messages nov08 ..not used
#define UBX_TIM 0x0D  // Timing messages: nov08 ..not used

// macro to return the length of cmd
#define UBXLEN(arg) ((arg)->len_HOB)*256 + ((arg)->len_LOB)

#define UBXOVHD 6			//cmd overhead bytes syncs, ids,len, but not CRC

#define UBX_SYNC_CHAR1    0xB5
#define UBX_SYNC_CHAR2    0x62


/*******************  UBX PROTOYPES            *****************/

/************** Function Declarations ****************************************/
extern long reverseLong(char *c);
extern void UBX_checksum(UBXPKT *cmd,
                         unsigned char *chk_a, unsigned char *chk_b);
                         
void          send_cmd         ( TUPort  *tup, UBXPKT *cmd );
short         UBX_parse        ( uchar c  );
//short         UBX_get_reply    ( TUPort  *tup, UBXPKT *cmd  );
short         UBX_get_reply    ( TUPort  *tup ); //oct11, cmd is global
short         UBX_flush_incoming(TUPort  *tup );
short         UBX_setport      ( TUPort  *tup );
short         check_UBX        ( void     );
short         UBX_Rst          ( TUPort  *tup );
short         UBX_cold         ( void     );
short         UBX_init         ( void     );
short         UBX_SVinfo       ( TUPort  *tup );
short         UBX_status       ( TUPort *tup, struct gps_param *gps );
short         UBX_GetTime      ( TUPort *tup, struct gps_param *gps );
short         UBX_SetRTC       ( void     );
short         UBX_NavSOL       ( TUPort *tup, struct gps_param *gps );
short         UBX_DOP          ( TUPort *tup, struct gps_param *gps );
short         UBX_LLA          ( TUPort *tup, struct gps_param *gps );
short         UBX_PosLLH       ( TUPort *tup );

extern int    UBX_setMsg       ( void);

extern void   Poll_Sat_Alm     ( short sat);
extern int    UBX_GetAlmanac   ( void);
extern int    UBX_SendAlmanac  ( void);

extern short  get_UBX          ( void  ); 
extern void   test_ubx         ( void  ); 

