// MATLAB2Network.h: interface for the CMATLAB2Network class.
//
//////////////////////////////////////////////////////////////////////

/*
 * MATLAB2Network.h
 *      
 *          Copyright (C) 2000 RasSimTech Ltd. 
 *
 *  This program is free software; you can redistribute it and/or
 *  modify it under the terms of the GNU General Public License
 *  as published by the Free Software Foundation; either version 2
 *  of the License, or (at your option) any later version. 
 *  This program is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 *  GNU General Public License for more details. 
 *  You should have received a copy of the GNU General Public License
 *  along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. 
 */


#if !defined(AFX_MATLAB2Network_H__786C3501_9678_44E7_A49B_128D38DBD780__INCLUDED_)
#define AFX_MATLAB2Network_H__786C3501_9678_44E7_A49B_128D38DBD780__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

#include <afx.h>
#include <afxwin.h>

#include <list>
typedef unsigned char   u_char;
#include "UserNetwork.h"
#include "ElapsedTime.h"

class CMATLAB2Network  
{
public:
	CMATLAB2Network();
	virtual ~CMATLAB2Network();

public:
	BOOL bTimeToSendPacket(double dDeltaTime);
	double dGetSimulationTime(){return(elapsedTime.dGetTimeSinceStartSec());};
	double dGetDT();

	void SetSendRateHz(double dSendRateHz){m_dSendRateHz=dSendRateHz;m_dSendPeriodSec=(m_dSendRateHz==0.0)?(0.05):(1.0/m_dSendRateHz);};
	double dGetSendRateHz(){return(m_dSendRateHz);};

	void SetSendTimerSec(double dSendTimerSec){m_dSendTimerSec=m_dSendTimerSec;};
	double dGetSendTimerSec(){return(m_dSendTimerSec);};

	BOOL bOpenConnection();
	void CloseConnection();
	BOOL bGetConnectionOpen(){return(m_bConnectionOpen);};

	BOOL bInitializeVehicle(int iCraftType,double dInitLongitude,double dInitLatitude,double dInitAltitude, char* pcVehicleName=NULL);
	BOOL bSendData();
	BOOL bReceiveData();

	Aircraft m_acftVehicleSend;		// storage for sending packets

	static std::list<Aircraft> m_lacftVehiclesReceive;	// storage que for received packets
	static void CALLBACK PacketHandler(Aircraft *pacftVehicle);
	

	BOOL& bGetUseRealTimeFlag(){return(m_bUseRealTimeFlag);};
	const BOOL& bGetUseRealTimeFlag()const{return(m_bUseRealTimeFlag);};
protected:
	double m_dSendPeriodSec;
	double m_dSendRateHz;
	double m_dSendTimerSec;
	static BOOL m_bConnectionOpen;	// only one network connection
	static int m_iNumberVehicles;	// need to keep track of number of vehicles to build unique ID numbers
	CElapsedTime elapsedTime;
	BOOL m_bFirstTimerTime;
	BOOL m_bUseRealTimeFlag;
};

#endif // !defined(AFX_MATLAB2Network_H__786C3501_9678_44E7_A49B_128D38DBD780__INCLUDED_)
