From 7d7e41dacc78c3e997b77a8b0be6b4fed8c1adf2 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 27 Sep 2000 18:00:04 +0000 Subject: [PATCH] Cleaned up a few poluting #defines. Did some fg -> sg name space updating (lots more to do but we'll get there eventually) --- simgear/constants.h | 5 ++- simgear/io/sg_socket.cxx | 18 +++++++- simgear/math/Makefile.am | 5 ++- simgear/math/localconsts.hxx | 42 +++++++++++++++++++ simgear/math/point3d.hxx | 2 + simgear/math/polar3d.hxx | 8 ++-- .../math/{fg_geodesy.cxx => sg_geodesy.cxx} | 16 +++---- .../math/{fg_geodesy.hxx => sg_geodesy.hxx} | 22 +++++----- simgear/timing/sg_time.cxx | 5 +++ 9 files changed, 95 insertions(+), 28 deletions(-) create mode 100644 simgear/math/localconsts.hxx rename simgear/math/{fg_geodesy.cxx => sg_geodesy.cxx} (96%) rename simgear/math/{fg_geodesy.hxx => sg_geodesy.hxx} (90%) diff --git a/simgear/constants.h b/simgear/constants.h index 63f6ad94..4347bd70 100644 --- a/simgear/constants.h +++ b/simgear/constants.h @@ -86,13 +86,14 @@ #define RESQ_FT 437882827922500. // ft #define RESQ_M 40680645877797.1344 // meter +#if 0 // Value of earth flattening parameter from ref [8] // // Note: FP = f // E = 1-f // EPS = sqrt(1-(1-f)^2) // - + #define FP 0.003352813178 #define E 0.996647186 #define EPS 0.081819221 @@ -103,7 +104,7 @@ #define MJD0 2415020.0 #define J2000 (2451545.0 - MJD0) #define SIDRATE .9972695677 - +#endif // Conversions diff --git a/simgear/io/sg_socket.cxx b/simgear/io/sg_socket.cxx index 43401357..6336e76b 100644 --- a/simgear/io/sg_socket.cxx +++ b/simgear/io/sg_socket.cxx @@ -215,15 +215,29 @@ bool SGSocket::open( SGProtocolDir dir ) { // this means client for now sock = make_client_socket(); - // TODO: check for error. + // TODO: check for error. if ( sock_style == SOCK_DGRAM ) { // Non-blocking UDP nonblock(); } + } else if ( dir == SG_IO_BI && sock_style == SOCK_STREAM ) { + // this means server for TCP sockets + + // Setup socket to listen on. Set "port" before making this + // call. A port of "0" indicates that we want to let the os + // pick any available port. + sock = make_server_socket(); + // TODO: check for error. + + FG_LOG( FG_IO, FG_INFO, "socket is connected to port = " << port ); + + // Blocking TCP + // Specify the maximum length of the connection queue + listen( sock, SG_MAX_SOCKET_QUEUE ); } else { FG_LOG( FG_IO, FG_ALERT, - "Error: bidirection mode not available yet for sockets." ); + "Error: bidirection mode not available for UDP sockets." ); return false; } diff --git a/simgear/math/Makefile.am b/simgear/math/Makefile.am index 6fad91b0..5ad69704 100644 --- a/simgear/math/Makefile.am +++ b/simgear/math/Makefile.am @@ -9,24 +9,25 @@ endif lib_LIBRARIES = libsgmath.a include_HEADERS = \ - fg_geodesy.hxx \ fg_memory.h \ fg_random.h \ interpolater.hxx \ leastsqs.hxx \ + localconsts.hxx \ point3d.hxx \ polar3d.hxx \ + sg_geodesy.hxx \ sg_types.hxx \ vector.hxx EXTRA_DIST = linintp2.h linintp2.inl sphrintp.h sphrintp.inl libsgmath_a_SOURCES = \ - fg_geodesy.cxx \ fg_random.c \ interpolater.cxx \ leastsqs.cxx \ polar3d.cxx \ + sg_geodesy.cxx \ vector.cxx INCLUDES += -I$(top_srcdir) $(ZLIB_INCL) diff --git a/simgear/math/localconsts.hxx b/simgear/math/localconsts.hxx new file mode 100644 index 00000000..14745e1e --- /dev/null +++ b/simgear/math/localconsts.hxx @@ -0,0 +1,42 @@ +// localconsts.hxx -- various constant that are shared +// +// Written by Curtis Olson, started September 2000. +// +// Copyright (C) 2000 Curtis L. Olson - curt@flightgear.org +// +// This library is free software; you can redistribute it and/or +// modify it under the terms of the GNU Library General Public +// License as published by the Free Software Foundation; either +// version 2 of the License, or (at your option) any later version. +// +// This library 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 +// Library General Public License for more details. +// +// You should have received a copy of the GNU Library General Public +// License along with this library; if not, write to the +// Free Software Foundation, Inc., 59 Temple Place - Suite 330, +// Boston, MA 02111-1307, USA. +// +// $Id$ + + +#ifndef _SG_LOCAL_CONSTS_HXX +#define _SG_LOCAL_CONSTS_HXX + + +// Value of earth flattening parameter from ref [8] +// +// Note: FP = f +// E = 1-f +// EPS = sqrt(1-(1-f)^2) +// + +static const double FP = 0.003352813178; +static const double E = 0.996647186; +static const double EPS = 0.081819221; +static const double INVG = 0.031080997; + + +#endif // _SG_LOCAL_CONSTS_HXX diff --git a/simgear/math/point3d.hxx b/simgear/math/point3d.hxx index 8ce271c3..26284a15 100644 --- a/simgear/math/point3d.hxx +++ b/simgear/math/point3d.hxx @@ -46,6 +46,8 @@ # include #endif +#include "localconsts.hxx" + // I don't understand ... or should be included // already depending on how you defined FG_HAVE_STD_INCLUDES, but I // can go ahead and add this -- CLO diff --git a/simgear/math/polar3d.hxx b/simgear/math/polar3d.hxx index 8dfc6a44..acd24ae7 100644 --- a/simgear/math/polar3d.hxx +++ b/simgear/math/polar3d.hxx @@ -40,13 +40,13 @@ // Find the Altitude above the Ellipsoid (WGS84) given the Earth // Centered Cartesian coordinate vector Distances are specified in // meters. -double fgGeodAltFromCart(const Point3D& cp); +double sgGeodAltFromCart(const Point3D& cp); // Convert a polar coordinate to a cartesian coordinate. Lon and Lat -// must be specified in radians. The FG convention is for distances +// must be specified in radians. The SG convention is for distances // to be specified in meters -inline Point3D fgPolarToCart3d(const Point3D& p) { +inline Point3D sgPolarToCart3d(const Point3D& p) { double tmp = cos( p.lat() ) * p.radius(); return Point3D( cos( p.lon() ) * tmp, @@ -57,7 +57,7 @@ inline Point3D fgPolarToCart3d(const Point3D& p) { // Convert a cartesian coordinate to polar coordinates (lon/lat // specified in radians. Distances are specified in meters. -inline Point3D fgCartToPolar3d(const Point3D& cp) { +inline Point3D sgCartToPolar3d(const Point3D& cp) { return Point3D( atan2( cp.y(), cp.x() ), FG_PI_2 - atan2( sqrt(cp.x()*cp.x() + cp.y()*cp.y()), cp.z() ), diff --git a/simgear/math/fg_geodesy.cxx b/simgear/math/sg_geodesy.cxx similarity index 96% rename from simgear/math/fg_geodesy.cxx rename to simgear/math/sg_geodesy.cxx index 506ae877..f376032d 100644 --- a/simgear/math/fg_geodesy.cxx +++ b/simgear/math/sg_geodesy.cxx @@ -1,4 +1,4 @@ -// fg_geodesy.cxx -- routines to convert between geodetic and geocentric +// sg_geodesy.cxx -- routines to convert between geodetic and geocentric // coordinate systems. // // Copied and adapted directly from LaRCsim/ls_geodesy.c @@ -21,7 +21,9 @@ #include #include "point3d.hxx" -#include "fg_geodesy.hxx" +#include "sg_geodesy.hxx" +#include "localconsts.hxx" + #ifndef FG_HAVE_NATIVE_SGI_COMPILERS FG_USING_STD(cout); @@ -31,7 +33,7 @@ FG_USING_STD(cout); #define ONE_SECOND 4.848136811E-6 -// fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r) +// sgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r) // INPUTS: // lat_geoc Geocentric latitude, radians, + = North // radius C.G. radius to earth center (meters) @@ -43,7 +45,7 @@ FG_USING_STD(cout); // local vertical (surface normal) of C.G. (meters) -void fgGeocToGeod( double lat_geoc, double radius, double +void sgGeocToGeod( double lat_geoc, double radius, double *lat_geod, double *alt, double *sea_level_r ) { double t_lat, x_alpha, mu_alpha, delt_mu, r_alpha, l_point, rho_alpha; @@ -89,7 +91,7 @@ void fgGeocToGeod( double lat_geoc, double radius, double // check for domain error if ( errno == EDOM ) { - FG_LOG( FG_GENERAL, FG_ALERT, "Domain ERROR in fgGeocToGeod!!!!" ); + FG_LOG( FG_GENERAL, FG_ALERT, "Domain ERROR in sgGeocToGeod!!!!" ); *sea_level_r = 0.0; } } @@ -97,7 +99,7 @@ void fgGeocToGeod( double lat_geoc, double radius, double } -// fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc ) +// sgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc ) // INPUTS: // lat_geod Geodetic latitude, radians, + = North // alt C.G. altitude above mean sea level (meters) @@ -109,7 +111,7 @@ void fgGeocToGeod( double lat_geoc, double radius, double // -void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, +void sgGeodToGeoc( double lat_geod, double alt, double *sl_radius, double *lat_geoc ) { double lambda_sl, sin_lambda_sl, cos_lambda_sl, sin_mu, cos_mu, px, py; diff --git a/simgear/math/fg_geodesy.hxx b/simgear/math/sg_geodesy.hxx similarity index 90% rename from simgear/math/fg_geodesy.hxx rename to simgear/math/sg_geodesy.hxx index cff20210..b9f7d6db 100644 --- a/simgear/math/fg_geodesy.hxx +++ b/simgear/math/sg_geodesy.hxx @@ -1,4 +1,4 @@ -// fg_geodesy.hxx -- routines to convert between geodetic and geocentric +// sg_geodesy.hxx -- routines to convert between geodetic and geocentric // coordinate systems. // // Copied and adapted directly from LaRCsim/ls_geodesy.c @@ -8,8 +8,8 @@ // $Id$ -#ifndef _FG_GEODESY_HXX -#define _FG_GEODESY_HXX +#ifndef _SG_GEODESY_HXX +#define _SG_GEODESY_HXX #ifndef __cplusplus @@ -21,7 +21,7 @@ #include -// fgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r) +// sgGeocToGeod(lat_geoc, radius, *lat_geod, *alt, *sea_level_r) // INPUTS: // lat_geoc Geocentric latitude, radians, + = North // radius C.G. radius to earth center (meters) @@ -32,11 +32,11 @@ // sea_level_r radius from earth center to sea level at // local vertical (surface normal) of C.G. (meters) -void fgGeocToGeod( double lat_geoc, double radius, double +void sgGeocToGeod( double lat_geoc, double radius, double *lat_geod, double *alt, double *sea_level_r ); -// fgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc ) +// sgGeodToGeoc( lat_geod, alt, *sl_radius, *lat_geoc ) // INPUTS: // lat_geod Geodetic latitude, radians, + = North // alt C.G. altitude above mean sea level (meters) @@ -47,27 +47,27 @@ void fgGeocToGeod( double lat_geoc, double radius, double // lat_geoc Geocentric latitude, radians, + = North // -void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, +void sgGeodToGeoc( double lat_geod, double alt, double *sl_radius, double *lat_geoc ); // convert a geodetic point lon(radians), lat(radians), elev(meter) to // a cartesian point -inline Point3D fgGeodToCart(const Point3D& geod) { +inline Point3D sgGeodToCart(const Point3D& geod) { double gc_lon, gc_lat, sl_radius; // printf("A geodetic point is (%.2f, %.2f, %.2f)\n", // geod[0], geod[1], geod[2]); gc_lon = geod.lon(); - fgGeodToGeoc(geod.lat(), geod.radius(), &sl_radius, &gc_lat); + sgGeodToGeoc(geod.lat(), geod.radius(), &sl_radius, &gc_lat); // printf("A geocentric point is (%.2f, %.2f, %.2f)\n", gc_lon, // gc_lat, sl_radius+geod[2]); Point3D pp = Point3D( gc_lon, gc_lat, sl_radius + geod.radius()); - return fgPolarToCart3d(pp); + return sgPolarToCart3d(pp); } @@ -172,4 +172,4 @@ $Header$ --------------------------------------------------------------------------*/ -#endif // _FG_GEODESY_HXX +#endif // _SG_GEODESY_HXX diff --git a/simgear/timing/sg_time.cxx b/simgear/timing/sg_time.cxx index f9467739..16d50d3e 100644 --- a/simgear/timing/sg_time.cxx +++ b/simgear/timing/sg_time.cxx @@ -63,6 +63,11 @@ #define RADHR(x) DEGHR(x*RAD_TO_DEG) +static const double MJD0 = 2415020.0; +static const double J2000 = 2451545.0 - MJD0; +static const double SIDRATE = 0.9972695677; + + SGTime::SGTime( double lon, double lat, const string& root ) { FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" ); -- 2.39.5