//
//	Global variables, constants and data structures for the GPS editor
//
//	Paul Nash
//	paul@frcs.alt.za

//
//	$Header: /usr/home/pilot/gypsy-1.6/RCS/globals.h,v 1.23 1999/08/30 06:35:32 paul Exp $
//
//	$Log: globals.h,v $
//	Revision 1.23  1999/08/30 06:35:32  paul
//	Added Jaque Andre's patches
//
//	Revision 1.22  1999/06/13 17:26:13  paul
//	Changed lat & long edit to use N/S E/W list (button) input, rather
//	than text.  This allows the ':' separator to use ' ' or '-'.
//
//	Revision 1.21  1999/06/12 14:38:39  paul
//	changed track log to allow cumulative logging.  Not tested yet
//
//	Revision 1.20  1999/05/12 08:48:05  paul
//	Ready for release as Gypsy 1.4.  Major changes include:
//	*  Rudimentary track/route buffer to transfer data between GPS
//	   and PC (a'la gps2p2pc)
//	*  Protocol fix for DLE escaping bug
//	*  Code changes from <andre@drfmc.ceng.cea.fr> to be able to
//	   compile a PalmOS2 version
//	*  Garmin protocol tries a bit harder to recover from comms
//	   errors (but is still *very* dumb)
//
//


#pragma pack(2)


//
//	Clever hack to get global variables defined correctly
//

#if ! defined (EXTERN)
#   define EXTERN extern
#endif // EXTERN


//
//	Some useful constants
//

#define DB_TYPE			'Data'
#define DB_APPID		'fRCS'
#define DB_NAME			"GPS Waypoint DB"
#define DB_ROUTE		'RteD'
#define DB_TRACK		'TrkD'

#define DLE			16
#define ETX			3

#define GARMIN_NAME_LEN		6
#define GARMIN_DESC_LEN		40

#define HOST_TRACK		0
#define HOST_ROUTE		1
#define HOST_WAYPOINT		2
#define GPS_TRACK		3
#define GPS_ROUTE		4
#define GPS_WAYPOINT		5

//
//	Data structures
//

struct waypoint {
   char name[GARMIN_NAME_LEN + 1];
   char descr[GARMIN_DESC_LEN + 1];
   int symbol;
   int display;
   long latitude;
   long longitude;
   int flagged;
   int changed;
   int record_num;
};


//
//	function protoypes in "garmin.c"
//

int GarminGetAll (int mode, UInt num_recs);
char *GarminLongToPos (long pos);
long GarminPosToLong (char *pos);
int GarminSend (Word command);
int GarminGetPos (long *lat, long *lon);
int OpenSerialPort (void);
int GarminGetPacket (char *buf, int *len, int *proto_err);
void SendAck (char type, int ack_or_nak);
void GarminSendPacket (char *buf, int len);
int GarminSendRaw (Word command);
int GarminSendTrack (void);
void GarminClearTrackLog (void);

//	... in "gps.c"

void setField (Word fieldname, char *contents);
void getField (Word fieldname, char *contents);
char *currentDBName (void);

//	... and "file.c"

Boolean HandleFileListEvent (EventPtr e);
Boolean HandleFileNewEvent (EventPtr e);

//	... and "host.c"

Boolean HandleHostEvent (EventPtr e);

//
//	The odd global variable ...
//

EXTERN DmOpenRef waypoint_db;
EXTERN int num_records;
EXTERN Word current_record;
EXTERN int table_top;
EXTERN VoidHand wpt_copy_buf;
EXTERN UInt serial_lib;
EXTERN int serial_port_open;
EXTERN Word newfile_camefrom;
EXTERN int file_merge;
