/********************************************************************\
|*	Portons Copyright © 1998 RasSimTech Ltd.                       	*|
|*	Printed in the United States of America.                       	*|
|*	All rights reserved.                                           	*|
|*	                                                               	*|
|*	This product or document is protected by copyright and         	*|
|*	distributed under licenses restricting its use,                	*|
|*	copyrightand distribution under licenses restricting           	*|
|*	its use, copying, distribution and decompilation.              	*|
|*	                                                               	*|
|*	No part of this product or document may be reproduced in       	*|
|*	any form by any means without prior written authorization of   	*|
|*	RasSimTech Ltd.							                     	*|
|*	                                                               	*|
\********************************************************************/
/************************************************************************\
|*	Copyright © 1997 Artificial Horizons, Inc..                    	*|
|*	Printed in the United States of America.                       	*|
|*	44 Montgomery. Suite 1480, San Francisco, CA, 94104 U.S.A.     	*|
|*	All rights reserved.                                           	*|
|*	                                                               	*|
|*	This product or document is protected by copyright and         	*|
|*	distributed under licenses restricting its use,                	*|
|*	copyrightand distribution under licenses restricting           	*|
|*	its use, copying, distribution and decompilation.              	*|
|*	                                                               	*|
|*	No part of this product or document may be reproduced in       	*|
|*	any form by any means without prior written authorization of   	*|
|*	Artificial Horizons, Inc. and its licensors.                   	*|
|*	                                                               	*|
|*	Artificial Horizons, Aviator, AVDS, FlightCam, ChaseCam,       	*|
|*	and TowerCam are trademarks or registered trademarks of        	*|
|*	of Artificial Horizons, Inc.                                   	*|
\************************************************************************/
 /***************************************************************************\
|*                                                                           *|
|* Copyright © 1989-1994 by Artificial Horizons®, Inc.  All rights reserved. *|
|*                                                                           *|
|*     This material  constitutes  the trade  secrets  and confidential,     *|
|*     proprietary information of Bruce Factor and Curtis Priem,  and is     *|
|*     under license  to Artificial Horizons, Inc.   The material is not     *|
|*     to be disclosed,  reproduced,  copied,  or used in any manner not     *|
|*     permitted under license from Artificial Horizons, Inc.   For more     *|
|*     information email "ahi-interest@ahi.com".                             *|
|*                                                                           *|
 \***************************************************************************/
/***************************************************************************\
|*                                                                           *|
|*                            Produced under:                                *|
|*        Cooperative Reasearch and Development Agreement 94-173-EL-02       *|
|*                               between                                     *|
|*                        Artificial Horizons®, Inc.                         *|
|*                                 and                                       *|
|*                    Wright Laboratory, WL/FIGS, USAF                       *|
|*                                                                           *|
|*                                  by                                       *|
|*           Robert R. Smith Jr. and Capt Steven J. Rasmussen                *|
|*                                1994-95                                    *|
|*                                                                           *|
\***************************************************************************/




#ifndef _USERNETWORK_h
#define _USERNETWORK_h

#include "UserNetworkErrors.h"

#define	AIRCRAFT_TYPE_00	0
#define	AIRCRAFT_TYPE_01	1
#define	AIRCRAFT_TYPE_02	2
#define	AIRCRAFT_TYPE_03	3
#define	AIRCRAFT_TYPE_04	4
#define	AIRCRAFT_TYPE_05	5
#define	AIRCRAFT_TYPE_06	6
#define	AIRCRAFT_TYPE_07	7
#define	AIRCRAFT_TYPE_08	8
#define	AIRCRAFT_TYPE_09	9
#define	AIRCRAFT_TYPE_10	10

#define PACKET_HANDLE_SIZE		(32)
#define SIZE_HOME_PORT (4)

#define MASK_NOTHING				(0x00000000)
#define MASK_CANOPY					(0x00000001)
#define MASK_ENGINE					(0x00000002)
#define MASK_ENGINE_PORT			(0x00000004)
#define MASK_ENGINE_STARBOARD		(0x00000008)
#define MASK_ENGINE_OPENING			(0x00000010)
#define MASK_ENGINE_OPENING_PORT	(0x00000020)
#define MASK_ENGINE_OPENING_STARBOARD	(0x00000040)
#define MASK_EXHAUST				(0x00000080)
#define MASK_EXHAUST_PORT			(0x00000100)
#define MASK_EXHAUST_STARBOARD		(0x00000200)
#define MASK_FUSELAGE				(0x00000400)
#define MASK_GEAR_FORE				(0x00000800)
#define MASK_GEAR_PORT				(0x00001000)
#define MASK_GEAR_STARBOARD			(0x00002000)
#define MASK_GEAR_OPENING_FORE		(0x00004000)
#define MASK_GEAR_OPENING_PORT		(0x00008000)
#define MASK_GEAR_OPENING_STARBOARD	(0x00010000)
#define MASK_ARTICULATED_SURFACE_01	(0x00020000)
#define MASK_ARTICULATED_SURFACE_02	(0x00040000)
#define MASK_ARTICULATED_SURFACE_03	(0x00080000)
#define MASK_ARTICULATED_SURFACE_04	(0x00100000)
#define MASK_ARTICULATED_SURFACE_05	(0x00200000)
#define MASK_ARTICULATED_SURFACE_06	(0x00400000)
#define MASK_ARTICULATED_SURFACE_07	(0x00800000)
#define MASK_ARTICULATED_SURFACE_08	(0x01000000)
#define MASK_ARTICULATED_SURFACE_09	(0x02000000)
#define MASK_ARTICULATED_SURFACE_10	(0x04000000)
#define MASK_ARTICULATED_SURFACE_11	(0x08000000)
#define MASK_ARTICULATED_SURFACE_12	(0x10000000)
#define MASK_ARTICULATED_SURFACE_13	(0x20000000)
#define MASK_ARTICULATED_SURFACE_14	(0x40000000)
#define MASK_BODY_AXES				(0x80000000)
#define MASK_EVERYTHING				(0x7fffffff)
#define MASK_GEAR ( MASK_GEAR_FORE | MASK_GEAR_PORT | MASK_GEAR_STARBOARD | \
								MASK_GEAR_OPENING_FORE | MASK_GEAR_OPENING_PORT | \
								MASK_GEAR_OPENING_STARBOARD )

#define STATUS_NO_EXTRAPOLATE	(0x0200)

#define USER_DATA_ElapsedSimulationTimeSec (0) 
#define USER_DATA_Articulated_Surface_01 (1) 
#define USER_DATA_Articulated_Surface_02 (2) 
#define USER_DATA_Articulated_Surface_03 (3) 
#define USER_DATA_Articulated_Surface_04 (4) 
#define USER_DATA_Articulated_Surface_05 (5) 
#define USER_DATA_Articulated_Surface_06 (6) 
#define USER_DATA_Articulated_Surface_07 (7) 
#define USER_DATA_Articulated_Surface_08 (8) 
#define USER_DATA_V_FeetSec (9) 
#define USER_DATA_Gs (10)
#define USER_DATA_Alpha_Rad (11)
#define USER_DATA_Beta_Rad (12)
#define USER_DATA_Filter_X (13)
#define USER_DATA_Filter_Y (14)
#define USER_DATA_Filter_Z (15)


typedef struct packet_struct Packet;
struct packet_struct  {	/* Description		Units */

	double dUserData[16];	/* for user supplied data */

	short current_cm_z;	/* center mass vertical	pseudo-half-inches          */
	short current_cm_y;	/* center mass fore	pseudo-half-inches          */
	short current_cm_x;	/* center mass starbord	pseudo-half-inches          */

	int view_Brot_y;	/* View left/right */
	int view_Brot_x;	/* View up/down */

	float Frot_dZ;	/* vertical  velocity	pseudo-third-minutes/sec    */
	float Frot_dY;	/* north     velocity	pseudo-third-minutes/sec    */
	float Frot_dX;	/* east      velocity	pseudo-third-minutes/sec    */
	int Brot_Z;	/* vertical  rotation	pseudo-third-minutes        */
	int Brot_Y;	/* north     rotation	pseudo-third-minutes        */
	int Brot_X;	/* east      rotation 	pseudo-third-minutes        */

	float Fpos_ddZ;	/* altitude  accelerate	pseudo-half-inches/sec/sec  */
	float Fpos_ddY;	/* latitude  accelerate	pseudo-half-inches/sec/sec  */
	float Fpos_ddX;	/* longitude accelerate	pseudo-half-inches/sec/sec  */
	float Fpos_dZ;	/* altitude  velocity	pseudo-half-inches/sec      */
	float Fpos_dY;	/* latitude  velocity	pseudo-half-inches/sec      */
	float Fpos_dX;	/* longitude velocity	pseudo-half-inches/sec      */

	int Ipos_Z;	/* altitude  linear	pseudo-half-inches          */
	int Ipos_Y;	/* latitude  linear	pseudo-half-inches          */
	int Ipos_X;	/* longitude linear	pseudo-half-inches          */

	float current_warhead;/*total warhead	pounds of TNT               */
	float current_fuel;	/* total fuel		pounds                      */
	int render_mask;	/* craft rendering mask	MASK_CANOPY,etc.            */

	int ground_Ipos_Z;	/* height of ground	pseudo-half-inches          */
	char ground_slope_Y;/* slope of the ground	unitless (Z/Y*128)          */
	char ground_slope_X;/* slope of the ground	unitless (Z/X*128)          */

	u_char ground_type;	/* object is over	GROUND_TYPE_WATER,etc.      */
	u_char engine;	/* engine level		ENGINE_MIN,ENGINE_MAX,etc.  */
	int craft_type;	/* craftcap type	0->INT_MAX craftcap order       */

	int collide_damage;/* unique craft id	MASK_WING_PORT,etc.         */
	int collide_craftid;/* unique craft id	unitless                    */
	int collide_hostid;/* hostid		unitless                    */
	int lockon_hostid;	/* hostid of target	unitless (0=nolock)         */
	int craft_checksum;/* crafttcap checksum	unitless                    */
	int craftid;	/* unique craft id	unitless                    */
	int hostid;	/* hostid		unitless                    */

	short status;	/* status		STATUS_LOCAL,etc.           */
	char home_port[SIZE_HOME_PORT];	/* Airport name		string			    */
	char handle[PACKET_HANDLE_SIZE];	 /*	string                      */
	int revision;	/* aviator revision	major,minor,patch           */

};

typedef struct aircraft_struct {
	int state;	/* aircraft state */
	float elev,ail,rud,throttle;/* commands */
	float u,v,w,p,q,r;
	/* Real values in world coordinates */
	double ref_X, ref_Y;			/* lat, long degrees */
	double pos_X, pos_Y;			/* ft. from ref, ft. alt. */
	double pos_Z;
	double pos_dX, pos_dY, pos_dZ;
	double rot_X, rot_Y, rot_Z;		/* deg */
	double rot_dX, rot_dY, rot_dZ;
	unsigned char engine;				/* throttle position */
	int hostid;
	Packet packet;
	float dt;	/*aircraft delta time*/
} Aircraft;



#ifdef __cplusplus
extern "C"{
int OpenAVDSNetwork(int,TCHAR *tcaAddresses[]);
int CloseAVDSNetwork();
int Init_Aircraft( Aircraft*, char*,int,int,float*,float*,float*);
int Put_Aircraft(Aircraft*);
int Get_Aircraft(void CALLBACK pAircraftCallback ( Aircraft *aP),Aircraft * aP);
int Put_Packet(Packet* P);
}
#else //#ifdef __cplusplus
int OpenAVDSNetwork();
int CloseAVDSNetwork();
int Init_Aircraft();
int Put_Aircraft();
int Get_Aircraft();
int Put_Packet();
#endif //#ifdef __cplusplus

#endif	//_USERNETWORK_h

/*
	if the STATUS_NO_EXTRAPOLATE bit is set in the status variable of the packet,
	as in the following example, then AVDS will not extrapolate the positions and
	rotations between packet updates. Also the following variables are set 
	using elements from the dUserData array in the packet:
	
	   Velocity in feet/second => dUserData[USER_DATA_V_FeetSec]
	   Gs  => dUserData[USER_DATA_Gs]
	   Angle of attack in radians => dUserData[USER_DATA_Alpha_Rad]
	   Sideslip Angle in radians => dUserData[USER_DATA_Beta_Rad]
	   filter parameters range from 0.0 to 1.0
	   Filter Parameter for X postion filters => dUserData[USER_DATA_Filter_X]
	   Filter Parameter for Y postion filters => dUserData[USER_DATA_Filter_Y]
	   Filter Parameter for Z postion filters => dUserData[USER_DATA_Filter_Z]

  FOR EXAMPLE:
	f18.packet.status |= STATUS_NO_EXTRAPOLATE;
	f18.packet.dUserData[USER_DATA_V_FeetSec] = 300;
	f18.packet.dUserData[USER_DATA_Gs] = 1.2;
	f18.packet.dUserData[USER_DATA_Alpha_Rad] = 0.0872664625997164788461845384244306;
	f18.packet.dUserData[USER_DATA_Beta_Rad] = 0.0872664625997164788461845384244306;
#define FILTER_PARAMETER (0.95)
	f18.packet.dUserData[USER_DATA_Filter_X] = FILTER_PARAMETER;
	f18.packet.dUserData[USER_DATA_Filter_Y] = FILTER_PARAMETER;
	f18.packet.dUserData[USER_DATA_Filter_Z] = FILTER_PARAMETER;

*/