2002-09-28 21:38:51 +00:00
|
|
|
// ExternalNet.hxx -- an net interface to an external flight dynamics model
|
|
|
|
//
|
|
|
|
// Written by Curtis Olson, started November 2001.
|
|
|
|
//
|
2004-11-19 22:10:41 +00:00
|
|
|
// Copyright (C) 2001 Curtis L. Olson - http://www.flightgear.org/~curt
|
2002-09-28 21:38:51 +00:00
|
|
|
//
|
|
|
|
// 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
|
2006-02-21 01:16:04 +00:00
|
|
|
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
|
2002-09-28 21:38:51 +00:00
|
|
|
//
|
|
|
|
// $Id$
|
|
|
|
|
|
|
|
#ifndef _EXTERNAL_NET_HXX
|
|
|
|
#define _EXTERNAL_NET_HXX
|
|
|
|
|
|
|
|
#include <plib/netBuffer.h>
|
|
|
|
#include <plib/netSocket.h>
|
|
|
|
|
2002-10-01 16:44:38 +00:00
|
|
|
#include <simgear/timing/timestamp.hxx> // fine grained timing measurements
|
|
|
|
|
2002-09-28 22:10:49 +00:00
|
|
|
#include <Network/net_ctrls.hxx>
|
2002-09-28 21:38:51 +00:00
|
|
|
#include <Network/net_fdm.hxx>
|
2006-04-17 13:19:53 +00:00
|
|
|
#include <FDM/flight.hxx>
|
2002-09-28 21:38:51 +00:00
|
|
|
|
|
|
|
|
|
|
|
class HTTPClient : public netBufferChannel
|
|
|
|
{
|
|
|
|
|
|
|
|
bool done;
|
2002-10-01 16:44:38 +00:00
|
|
|
SGTimeStamp start;
|
2002-09-28 21:38:51 +00:00
|
|
|
|
|
|
|
public:
|
|
|
|
|
2004-03-22 15:00:42 +00:00
|
|
|
HTTPClient ( const char* host, int port, const char* path ) :
|
2002-09-28 21:38:51 +00:00
|
|
|
done( false )
|
|
|
|
{
|
|
|
|
open ();
|
|
|
|
connect (host, port);
|
|
|
|
|
2004-03-22 15:00:42 +00:00
|
|
|
const char* s = netFormat ( "GET %s HTTP/1.0\r\n\r\n", path );
|
2002-09-28 21:38:51 +00:00
|
|
|
bufferSend( s, strlen(s) ) ;
|
2002-10-01 16:44:38 +00:00
|
|
|
|
|
|
|
start.stamp();
|
2002-09-28 21:38:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
virtual void handleBufferRead (netBuffer& buffer)
|
|
|
|
{
|
|
|
|
const char* s = buffer.getData();
|
|
|
|
while (*s)
|
|
|
|
fputc(*s++,stdout);
|
|
|
|
|
|
|
|
printf("done\n");
|
|
|
|
buffer.remove();
|
|
|
|
printf("after buffer.remove()\n");
|
|
|
|
done = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
bool isDone() const { return done; }
|
2002-10-01 16:44:38 +00:00
|
|
|
bool isDone( long usec ) const {
|
|
|
|
SGTimeStamp now;
|
|
|
|
now.stamp();
|
|
|
|
if ( (now - start) > usec ) {
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return done;
|
|
|
|
}
|
|
|
|
}
|
2002-09-28 21:38:51 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
class FGExternalNet: public FGInterface {
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
int data_in_port;
|
|
|
|
int data_out_port;
|
|
|
|
int cmd_port;
|
|
|
|
string fdm_host;
|
|
|
|
|
|
|
|
netSocket data_client;
|
|
|
|
netSocket data_server;
|
|
|
|
|
|
|
|
bool valid;
|
|
|
|
|
2002-09-28 22:10:49 +00:00
|
|
|
FGNetCtrls ctrls;
|
2002-09-28 21:38:51 +00:00
|
|
|
FGNetFDM fdm;
|
|
|
|
|
|
|
|
public:
|
|
|
|
|
|
|
|
// Constructor
|
|
|
|
FGExternalNet( double dt, string host, int dop, int dip, int cp );
|
|
|
|
|
|
|
|
// Destructor
|
|
|
|
~FGExternalNet();
|
|
|
|
|
|
|
|
// Reset flight params to a specific position
|
|
|
|
void init();
|
|
|
|
|
|
|
|
// update the fdm
|
|
|
|
void update( double dt );
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif // _EXTERNAL_NET_HXX
|