// IPC_com.h
// Copyright (c) 1999-2000 ACSoft Productions.  All rights reserved.
//
// Definition of IPC shared memory blocks for
// communication with ACS-GPS98 gauges

// Version: 1.10

// ****************************************************************

//  All ACS-GPS98 gauges version 1.60 and over include now two IPC
//  Memory blocks for external communication purposes.
//
// In this new 1.10 version, both following IPC block name has been
// changed to avoid conflict with older 1.0 version.
//
// The main one is called: ACSGPS98_COM_IPC_11
// This block return all useful flight parameters and allow to
// externaly command GPS to reload program, to change Status and
// select the active leg of the current program (remote controls).
//
// The second one is called: ACSGPS98_PGR_IPC_11
// This block is a copy of the internal GPS program structure.
//
// You will found here after all required definitions to access both
// blocks. This include useful general comments under REMARKS
//
// For usage of IPC shared memory block, please refer to Microsoft
// documentation. I will not answer to any question related to the
// usage of this Microsoft feature.
//
// For questions specific to ACS-GPS98 IPC feature, I will try to
// do my best, but I cannot guarantee a support. Therefore, it is
// possible that questions you may E-Mail to me, remain without
// any answer (sorry).

// ****************************************************************


// Coordinates structure
typedef struct Coord {
	char Id;			// can be either 'E', 'W', 'N' or 'S'
	unsigned int D;		// in degrees (0 to 179 or 0 to 89)
	unsigned int M;		// in minutes (0 to 59)
	unsigned int S;		// second (0 to 59)
	double Md;			// degrees.decimal (FS98 format)
} CRD, *PCRD;

// Leg structure (one item of a GPS progr)
#define LgIdent 5
#define LgName 20
typedef struct Lg {
	char Ident[LgIdent+1];	// Leg ident
	char Name[LgName+1];	// Leg Name
	CRD LegLon;			// Leg longitude coordinate
	CRD LegLat;			// Leg Latitude coordinate
} LEG;

// GPS program
#define MaxLeg 99
typedef LEG PGR[MaxLeg];	// array of 99 legs 


// Name of COM IPC memory block
#define IPC_COM_AREA_NAME "ACSGPS98_COM_IPC_11"

// IPC COM data structure
typedef struct ComSet {
	CRD Lat;			// actual latitude of aircraft [OUT]
	CRD Lon;			// actual longitude of aircraft [OUT]
	int GPS_Hdg;		// GPS great circle heading to next waypoint [OUT]
	int GPS_ApHdg;		// GPS autopilot heading to reach next waypoint [OUT]
	int Hdg;			// actual real aircraft heading [OUT]
	int Altitude;		// actual aircraft altitude [OUT]
	int GrSpeed;		// actual aircraft ground speed (TAS in knots) [OUT]
	double Dist;		// actual distance to next waypoint in nm [OUT]
	int ETA_Hour;		// estimated time hours to waypoint [OUT]
	int ETA_Min;		// estimated time minutes to waypoint [OUT]
	BOOL GPS_Status;	// TRUE if GPS active (linked to autopilot) [IN/OUT]
	BOOL WDC_Active;	// TRUE if wind drift comp is active [OUT]
	BOOL Invalid_ApHdg;	// if TRUE indicate ApHdg is invalid [OUT]
	int PgrIdent;		// identification number of progr (zero if invalid progr) [OUT]
	int NbrLeg;			// number of waypoint(s) into program [OUT]
	int CurLegIndex;	// current leg index [IN/OUT]
	int GPS_Online;		// IPC block status (see remarks) [OUT]
	BOOL Reload;		// Set externaly TRUE will force GPS program to reload [IN]
	BOOL RemoteSet;		// Set externaly TRUE will force GPS to accept settings [IN]
	BOOL PowerFail;		// Set externaly TRUE instruct GPS power is not anymore there [IN] 
} COMSET;




// Name of PGR IPC memory block
#define IPC_PGR_AREA_NAME "ACSGPS98_PGR_IPC_11"

	PGR GPS_Progr;		// GPS loaded program


// REMARKS
//
// IMPORTANT: all gauges are compiled with "Struct member aligment"
// generation code parameter set to "1 BYTE". To be compatible with
// Visual Basic. You must not forget to use same aligment in your
// own code.
//
// Mutual exclusion ressource has not been implemented. Hours of tests
// I made on this subject never proved this security feature was really
// required here. I simply never experienced a dead lock without Mutex.
//
// All headings are magnetic headings.
//
// Both GPS heading will have a different value, only when wind drift
// compensation is active. They can be totally different from aircraft
// Hdg if GPS is not coupled with autopilot and pilot follow an
// other heading.
//
// GPS_Hdg is always pointing to next waypoint (great circle heading).
//
// GPS_ApHdg is the heading aircraft must follow to reach the next
// waypoint. Invalid_ApHdg indicate if this heading is valid or not.
// This mean, if aircraft is still able to compensate wind drift.
//
// PgrIdent is an unique number (checksum) of the actual GPS program
// By checking this number, user can know if program has changed and
// then read ACSGPS98_PGR_IPC_11 block.
//
// When PgrIdent is NULL, this mean an error occur during GPS progr
// loading. User can still read ACSGPS98_PGR_IPC_11 block if he want to.
// In this case, we have a pseudo progr of one unique leg, reporting
// in Ident and Name the encountered error (other fields invalid).
//
// GPS_Online tell you if a GPS is switched to the IPC block and
// update it. Zero mean no GPS is linked with IPC block. If GPS has
// an ON/OFF feature, like the KLN90B, GPS_Online will also report
// zero when the GPS is switched OFF. Will be the same with Power
// failure feature, if supported by the gauge. When non zero, we have
// a GPS and GPS_Online is a GPS model identifier:
//   1 = ACS.GPS98-V1.gau
//   2 = ACS.GPS98-V2.gau
//   3 = ACS.GPS98-V3.gau
//   4 = ACS.GPS98-V4.gau
// 101 = ACS.GPS98-KLN90B_CRT.gau
// 102 = ACS.GPS98-KLN90B_LCD.gau
// 201 = ACS.GPS98-LEARJET.gau
// 301 = ACS.GPS98-Concorde.gau
//
// ACSGPS98_COM_IPC block is refreshed every second. ACSGPS98_PGR_IPC_11
// is obviously refreshed only when GPS program change.
//
// PowerFail variable is pooled at full speed (18 times per second)
// by GPS gauges supporting POWER feature (all except Concorde version).
// As soon as this variable is set externally TRUE, GPS will simulate
// a power failure and will come to a dead state until this variable
// is restored to FALSE state.
//
// ATTENTION never forget that a gauge goes to an idle state when the
// window which carry it is not anymore open or active. It is the case
// when user select outside view or if the window is simply not open.
// In this case, all IPC communications are blocked. GPS gauge will not
// refresh IPC memory blocks nor execute RemoteSet commands. In this
// particular case, GPS_online will NOT reflect this state. Watching
// Lat/Lon variables may be a way to detect this state, almost when
// aircraft is in flight an not supposed to be an hovering helicopter!
//
// Reload can be set TRUE externaly, to force GPS gauge to reload the
// GPS program (file ACS-GPS.dat into FS98 root directory) Prealably,
// user will have overwrited this file with a valid GPS program file.
// In any cases, syntax control will occur during loading.
//
// RemoteSet can be set TRUE, to tell to GPS to read and use both
// [IN/OUT] variables GPS_Status & CurLegIndex from IPC memory.
// Given CurLegIndex is over/underflow controlled. This feature
// let user command remotely the GPS gauge.
//
// For both Reload and RemoteSet, GPS gauge will return the variable
// to FALSE as an aknowledge remote orders has been done.
