INPUT = \
simgear/bucket \
simgear/compiler.h \
- simgear/constants.h
+ simgear/constants.h \
+ simgear/debug
# If the value of the INPUT tag contains directories, you can use the
# FILE_PATTERNS tag to specify one or more wildcard pattern (like *.cpp
# define SG_USING_NAMESPACE(X)
#endif
+/** \def SG_USING_STD(x)
+ * Expands to using std::x if SG_HAVE_STD is defined
+ */
# ifdef SG_HAVE_STD
# define SG_USING_STD(X) using std::X
# define STD std
-// NB: To add a dbg_class, add it here, and add it to the structure in
-// fg_debug.c
+/** \file debug_types.h
+ * Define the various logging classes and prioritiess
+ */
+/**
+ * Define the possible classes/categories of logging messages
+ */
typedef enum {
- FG_NONE = 0x00000000,
+ SG_NONE = 0x00000000,
- FG_TERRAIN = 0x00000001,
- FG_ASTRO = 0x00000002,
- FG_FLIGHT = 0x00000004,
- FG_INPUT = 0x00000008,
- FG_GL = 0x00000010,
- FG_VIEW = 0x00000020,
- FG_COCKPIT = 0x00000040,
- FG_GENERAL = 0x00000080,
- FG_MATH = 0x00000100,
- FG_EVENT = 0x00000200,
- FG_AIRCRAFT = 0x00000400,
- FG_AUTOPILOT = 0x00000800,
- FG_IO = 0x00001000,
- FG_CLIPPER = 0x00002000,
- FG_NETWORK = 0x00004000,
- FG_UNDEFD = 0x00008000, // For range checking
+ SG_TERRAIN = 0x00000001,
+ SG_ASTRO = 0x00000002,
+ SG_FLIGHT = 0x00000004,
+ SG_INPUT = 0x00000008,
+ SG_GL = 0x00000010,
+ SG_VIEW = 0x00000020,
+ SG_COCKPIT = 0x00000040,
+ SG_GENERAL = 0x00000080,
+ SG_MATH = 0x00000100,
+ SG_EVENT = 0x00000200,
+ SG_AIRCRAFT = 0x00000400,
+ SG_AUTOPILOT = 0x00000800,
+ SG_IO = 0x00001000,
+ SG_CLIPPER = 0x00002000,
+ SG_NETWORK = 0x00004000,
+ SG_UNDEFD = 0x00008000, // For range checking
- FG_ALL = 0xFFFFFFFF
-} fgDebugClass;
+ SG_ALL = 0xFFFFFFFF
+} sgDebugClass;
-// NB: To add a priority, add it here.
+/**
+ * Define the possible logging priorities (and their order).
+ */
typedef enum {
- FG_BULK, // For frequent messages
- FG_DEBUG, // Less frequent debug type messages
- FG_INFO, // Informatory messages
- FG_WARN, // Possible impending problem
- FG_ALERT // Very possible impending problem
- // FG_EXIT, // Problem (no core)
- // FG_ABORT // Abandon ship (core)
-} fgDebugPriority;
-
+ SG_BULK, // For frequent messages
+ SG_DEBUG, // Less frequent debug type messages
+ SG_INFO, // Informatory messages
+ SG_WARN, // Possible impending problem
+ SG_ALERT // Very possible impending problem
+ // SG_EXIT, // Problem (no core)
+ // SG_ABORT // Abandon ship (core)
+} sgDebugPriority;
#include "logstream.hxx"
bool logbuf::logging_enabled = true;
-fgDebugClass logbuf::logClass = FG_NONE;
-fgDebugPriority logbuf::logPriority = FG_INFO;
+sgDebugClass logbuf::logClass = SG_NONE;
+sgDebugPriority logbuf::logPriority = SG_INFO;
streambuf* logbuf::sbuf = NULL;
logbuf::logbuf()
}
void
-logbuf::set_log_level( fgDebugClass c, fgDebugPriority p )
+logbuf::set_log_level( sgDebugClass c, sgDebugPriority p )
{
logClass = c;
logPriority = p;
}
void
-logstream::setLogLevels( fgDebugClass c, fgDebugPriority p )
+logstream::setLogLevels( sgDebugClass c, sgDebugPriority p )
{
logbuf::set_log_level( c, p );
}
-// Stream based logging mechanism.
-//
+/** \file logstream.hxx
+ * Stream based logging mechanism.
+ */
+
// Written by Bernie Bright, 1998
//
// Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au
# include <config.h>
#endif
-
#include <simgear/compiler.h>
// At least Irix needs this
// 3. Read environment for default debugClass and debugPriority.
//
-//-----------------------------------------------------------------------------
-//
-// logbuf is an output-only streambuf with the ability to disable sets of
-// messages at runtime. Only messages with priority >= logbuf::logPriority
-// and debugClass == logbuf::logClass are output.
-//
+/**
+ * logbuf is an output-only streambuf with the ability to disable sets of
+ * messages at runtime. Only messages with priority >= logbuf::logPriority
+ * and debugClass == logbuf::logClass are output.
+ */
class logbuf : public streambuf
{
public:
// typedef char_traits<char>::pos_type pos_type;
// typedef char_traits<char>::off_type off_type;
#endif
-// logbuf( streambuf* sb ) : sbuf(sb) {}
+ // logbuf( streambuf* sb ) : sbuf(sb) {}
+ /** Constructor */
logbuf();
+ /** Destructor */
~logbuf();
- // Is logging enabled?
+ /** Is logging enabled? */
bool enabled() { return logging_enabled; }
- // Set the logging level of subsequent messages.
- void set_log_state( fgDebugClass c, fgDebugPriority p );
+ /** Set the logging level of subsequent messages. */
+ void set_log_state( sgDebugClass c, sgDebugPriority p );
- // Set the global logging level.
- static void set_log_level( fgDebugClass c, fgDebugPriority p );
+ /** Set the global logging level. */
+ static void set_log_level( sgDebugClass c, sgDebugPriority p );
- //
+ /** Set the stream buffer */
void set_sb( streambuf* sb );
protected:
+ /** sync/flush */
inline virtual int sync();
+
+ /** overflow */
int_type overflow( int ch );
-// int xsputn( const char* s, istreamsize n );
+ // int xsputn( const char* s, istreamsize n );
private:
static streambuf* sbuf;
static bool logging_enabled;
- static fgDebugClass logClass;
- static fgDebugPriority logPriority;
+ static sgDebugClass logClass;
+ static sgDebugPriority logPriority;
private:
}
inline void
-logbuf::set_log_state( fgDebugClass c, fgDebugPriority p )
+logbuf::set_log_state( sgDebugClass c, sgDebugPriority p )
{
logging_enabled = ((c & logClass) != 0 && p >= logPriority);
}
return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0);
}
-//-----------------------------------------------------------------------------
-//
-// logstream manipulator for setting the log level of a message.
-//
+/**
+ * logstream manipulator for setting the log level of a message.
+ */
struct loglevel
{
- loglevel( fgDebugClass c, fgDebugPriority p )
+ loglevel( sgDebugClass c, sgDebugPriority p )
: logClass(c), logPriority(p) {}
- fgDebugClass logClass;
- fgDebugPriority logPriority;
+ sgDebugClass logClass;
+ sgDebugPriority logPriority;
};
-//-----------------------------------------------------------------------------
-//
-// A helper class that ensures a streambuf and ostream are constructed and
-// destroyed in the correct order. The streambuf must be created before the
-// ostream but bases are constructed before members. Thus, making this class
-// a private base of logstream, declared to the left of ostream, we ensure the
-// correct order of construction and destruction.
-//
+/**
+ * A helper class that ensures a streambuf and ostream are constructed and
+ * destroyed in the correct order. The streambuf must be created before the
+ * ostream but bases are constructed before members. Thus, making this class
+ * a private base of logstream, declared to the left of ostream, we ensure the
+ * correct order of construction and destruction.
+ */
struct logstream_base
{
-// logstream_base( streambuf* sb ) : lbuf(sb) {}
+ // logstream_base( streambuf* sb ) : lbuf(sb) {}
logstream_base() {}
logbuf lbuf;
};
-//-----------------------------------------------------------------------------
-//
-//
-//
+/**
+ * Class to manage the debug logging stream.
+ */
class logstream : private logstream_base, public ostream
{
public:
- // The default is to send messages to cerr.
+ /** The default is to send messages to cerr. */
logstream( ostream& out )
-// : logstream_base(out.rdbuf()),
+ // : logstream_base(out.rdbuf()),
: logstream_base(),
ostream(&lbuf) { lbuf.set_sb(out.rdbuf());}
+ /** Set the output stream */
void set_output( ostream& out ) { lbuf.set_sb( out.rdbuf() ); }
- // Set the global log class and priority level.
- void setLogLevels( fgDebugClass c, fgDebugPriority p );
+ /** Set the global log class and priority level. */
+ void setLogLevels( sgDebugClass c, sgDebugPriority p );
- // Output operator to capture the debug level and priority of a message.
+ /** Output operator to capture the debug level and priority of a message. */
inline ostream& operator<< ( const loglevel& l );
};
return *this;
}
-//-----------------------------------------------------------------------------
-//
-// Return the one and only logstream instance.
-// We use a function instead of a global object so we are assured that cerr
-// has been initialised.
-//
+
+/**
+ * Return the one and only logstream instance.
+ * We use a function instead of a global object so we are assured that cerr
+ * has been initialised.
+ */
inline logstream&
-fglog()
+sglog()
{
static logstream logstrm( cerr );
return logstrm;
}
+
+/** \def SG_LOG(C,P,M)
+ * Log a message = M of class = C and priority = P
+ */
#ifdef FG_NDEBUG
-# define FG_LOG(C,P,M)
+# define SG_LOG(C,P,M)
#elif defined( __MWERKS__ )
-# define FG_LOG(C,P,M) ::fglog() << ::loglevel(C,P) << M << std::endl
+# define SG_LOG(C,P,M) ::sglog() << ::loglevel(C,P) << M << std::endl
#else
-# define FG_LOG(C,P,M) fglog() << loglevel(C,P) << M << endl
+# define SG_LOG(C,P,M) sglog() << loglevel(C,P) << M << endl
#endif
+
#endif // _LOGSTREAM_H
int
main( int argc, char* argv[] )
{
- fglog().setLogLevels( FG_ALL, FG_INFO );
+ fglog().setLogLevels( SG_ALL, SG_INFO );
- FG_LOG( FG_TERRAIN, FG_BULK, "terrain::bulk" ); // shouldnt appear
- FG_LOG( FG_TERRAIN, FG_DEBUG, "terrain::debug" ); // shouldnt appear
- FG_LOG( FG_TERRAIN, FG_INFO, "terrain::info" );
- FG_LOG( FG_TERRAIN, FG_WARN, "terrain::warn" );
- FG_LOG( FG_TERRAIN, FG_ALERT, "terrain::alert" );
+ SG_LOG( FG_TERRAIN, FG_BULK, "terrain::bulk" ); // shouldnt appear
+ SG_LOG( FG_TERRAIN, SG_DEBUG, "terrain::debug" ); // shouldnt appear
+ SG_LOG( FG_TERRAIN, SG_INFO, "terrain::info" );
+ SG_LOG( FG_TERRAIN, FG_WARN, "terrain::warn" );
+ SG_LOG( FG_TERRAIN, SG_ALERT, "terrain::alert" );
int i = 12345;
long l = 54321L;
double d = 3.14159;
string s = "Hello world!";
- FG_LOG( FG_EVENT, FG_INFO, "event::info "
+ SG_LOG( SG_EVENT, SG_INFO, "event::info "
<< "i=" << i
<< ", l=" << l
<< ", d=" << d
<< ", s=\"" << s << "\"" );
// This shouldn't appear in log output:
- FG_LOG( FG_EVENT, FG_DEBUG, "event::debug "
+ SG_LOG( SG_EVENT, SG_DEBUG, "event::debug "
<< "- this should be seen - "
<< "d=" << d
<< ", s=\"" << s << "\"" );
ze = yg * sin(ecl) + zg * cos(ecl);
rightAscension = atan2(ye, xe);
declination = atan2(ze, sqrt(xe*xe + ye*ye));
- /* FG_LOG(FG_GENERAL, FG_INFO, "Planet found at : "
+ /* SG_LOG(SG_GENERAL, SG_INFO, "Planet found at : "
<< rightAscension << " (ra), " << declination << " (dec)" ); */
//calculate some variables specific to calculating the magnitude
r += (-0.58 * cos(M - 2*D)
-0.46 * cos(2*D)
);
- // FG_LOG(FG_GENERAL, FG_INFO, "Running moon update");
+ // SG_LOG(SG_GENERAL, SG_INFO, "Running moon update");
xg = r * cos(lonEcl) * cos(latEcl);
yg = r * sin(lonEcl) * cos(latEcl);
zg = r * sin(latEcl);
geoRa = atan2(ye, xe);
geoDec = atan2(ze, sqrt(xe*xe + ye*ye));
- /* FG_LOG( FG_GENERAL, FG_INFO,
+ /* SG_LOG( SG_GENERAL, SG_INFO,
"(geocentric) geoRa = (" << (SGD_RADIANS_TO_DEGREES * geoRa)
<< "), geoDec= (" << (SGD_RADIANS_TO_DEGREES * geoDec) << ")" ); */
// First calculate the moon's parrallax, that is, the apparent size of the
// (equatorial) radius of the earth, as seen from the moon
mpar = asin ( 1 / r);
- // FG_LOG( FG_GENERAL, FG_INFO, "r = " << r << " mpar = " << mpar );
- // FG_LOG( FG_GENERAL, FG_INFO, "lat = " << f->get_Latitude() );
+ // SG_LOG( SG_GENERAL, SG_INFO, "r = " << r << " mpar = " << mpar );
+ // SG_LOG( SG_GENERAL, SG_INFO, "lat = " << f->get_Latitude() );
gclat = lat - 0.003358 *
sin (2 * SGD_DEGREES_TO_RADIANS * lat );
- // FG_LOG( FG_GENERAL, FG_INFO, "gclat = " << gclat );
+ // SG_LOG( SG_GENERAL, SG_INFO, "gclat = " << gclat );
rho = 0.99883 + 0.00167 * cos(2 * SGD_DEGREES_TO_RADIANS * lat);
- // FG_LOG( FG_GENERAL, FG_INFO, "rho = " << rho );
+ // SG_LOG( SG_GENERAL, SG_INFO, "rho = " << rho );
if (geoRa < 0)
geoRa += (2*SGD_PI);
HA = lst - (3.8197186 * geoRa);
- /* FG_LOG( FG_GENERAL, FG_INFO, "t->getLst() = " << t->getLst()
+ /* SG_LOG( SG_GENERAL, SG_INFO, "t->getLst() = " << t->getLst()
<< " HA = " << HA ); */
g = atan (tan(gclat) / cos ((HA / 3.8197186)));
- // FG_LOG( FG_GENERAL, FG_INFO, "g = " << g );
+ // SG_LOG( SG_GENERAL, SG_INFO, "g = " << g );
rightAscension = geoRa - mpar * rho * cos(gclat) * sin(HA) / cos (geoDec);
declination = geoDec - mpar * rho * sin (gclat) * sin (g - geoDec) / sin(g);
- /* FG_LOG( FG_GENERAL, FG_INFO,
+ /* SG_LOG( SG_GENERAL, SG_INFO,
"Ra = (" << (SGD_RADIANS_TO_DEGREES *rightAscension)
<< "), Dec= (" << (SGD_RADIANS_TO_DEGREES *declination) << ")" ); */
}
// build the full path name to the stars data base file
data_path.append( "stars" );
- FG_LOG( FG_ASTRO, FG_INFO, " Loading stars from " << data_path.str() );
+ SG_LOG( SG_ASTRO, SG_INFO, " Loading stars from " << data_path.str() );
fg_gzifstream in( data_path.str() );
if ( ! in.is_open() ) {
- FG_LOG( FG_ASTRO, FG_ALERT, "Cannot open star file: "
+ SG_LOG( SG_ASTRO, SG_ALERT, "Cannot open star file: "
<< data_path.str() );
exit(-1);
}
++nstars;
}
- FG_LOG( FG_ASTRO, FG_INFO, " Loaded " << nstars << " stars" );
+ SG_LOG( SG_ASTRO, SG_INFO, " Loaded " << nstars << " stars" );
return true;
}
} else if ( get_dir() == SG_IO_IN ) {
fp = ::open( file_name.c_str(), O_RDONLY );
} else {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: bidirection mode not available for files." );
return false;
}
if ( fp == -1 ) {
- FG_LOG( FG_IO, FG_ALERT, "Error opening file: " << file_name );
+ SG_LOG( SG_IO, SG_ALERT, "Error opening file: " << file_name );
return false;
}
int SGFile::write( const char *buf, const int length ) {
int result = ::write( fp, buf, length );
if ( result != length ) {
- FG_LOG( FG_IO, FG_ALERT, "Error writing data: " << file_name );
+ SG_LOG( SG_IO, SG_ALERT, "Error writing data: " << file_name );
}
return result;
set_dir( d );
if ( ! port.open_port( device ) ) {
- FG_LOG( FG_IO, FG_ALERT, "Error opening device: " << device );
+ SG_LOG( SG_IO, SG_ALERT, "Error opening device: " << device );
return false;
}
// cout << "fd = " << port.fd << endl;
if ( ! port.set_baud( atoi( baud.c_str() ) ) ) {
- FG_LOG( FG_IO, FG_ALERT, "Error setting baud: " << baud );
+ SG_LOG( SG_IO, SG_ALERT, "Error setting baud: " << baud );
return false;
}
// copy to external buffer
strncpy( buf, save_buf, result );
buf[result] = '\0';
- FG_LOG( FG_IO, FG_INFO, "fg_serial line = " << buf );
+ SG_LOG( SG_IO, SG_INFO, "fg_serial line = " << buf );
// shift save buffer
for ( i = result; i < save_len; ++i ) {
int result = port.write_port( buf, length );
if ( result != length ) {
- FG_LOG( FG_IO, FG_ALERT, "Error writing data: " << device );
+ SG_LOG( SG_IO, SG_ALERT, "Error writing data: " << device );
}
return result;
{
#if defined(_MSC_VER)
if (!wsock_init && !wsastartup()) {
- FG_LOG( FG_IO, FG_ALERT, "Winsock not available");
+ SG_LOG( SG_IO, SG_ALERT, "Winsock not available");
}
#endif
sock_style = SOCK_STREAM;
} else {
sock_style = SOCK_DGRAM;
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: SGSocket() unknown style = " << style );
}
// Create the socket.
sock = socket (PF_INET, sock_style, 0);
if (sock == INVALID_SOCKET) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: socket() failed in make_server_socket()" );
return INVALID_SOCKET;
}
name.sin_port = htons(port); // set port to zero to let system pick
name.sin_addr.s_addr = htonl (INADDR_ANY);
if (bind (sock, (struct sockaddr *) &name, sizeof (name)) != 0) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: bind() failed in make_server_socket()" );
return INVALID_SOCKET;
}
// Find the assigned port number
length = sizeof(struct sockaddr_in);
if ( getsockname(sock, (struct sockaddr *) &name, &length) ) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: getsockname() failed in make_server_socket()" );
return INVALID_SOCKET;
}
struct sockaddr_in name;
struct hostent *hp;
- FG_LOG( FG_IO, FG_INFO, "Make client socket()" );
+ SG_LOG( SG_IO, SG_INFO, "Make client socket()" );
// Create the socket.
sock = socket (PF_INET, sock_style, 0);
if (sock == INVALID_SOCKET) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: socket() failed in make_server_socket()" );
return INVALID_SOCKET;
}
sizeof(struct sockaddr_in)) != 0 )
{
closesocket(sock);
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: connect() failed in make_client_socket()" );
return INVALID_SOCKET;
}
// pick any available port.
sock = make_server_socket();
if ( sock == INVALID_SOCKET ) {
- FG_LOG( FG_IO, FG_ALERT, "socket creation failed" );
+ SG_LOG( SG_IO, SG_ALERT, "socket creation failed" );
return false;
}
- FG_LOG( FG_IO, FG_INFO, "socket is connected to port = " << port );
+ SG_LOG( SG_IO, SG_INFO, "socket is connected to port = " << port );
if ( sock_style == SOCK_DGRAM ) {
// Non-blocking UDP
sock = make_server_socket();
// TODO: check for error.
- FG_LOG( FG_IO, FG_INFO, "socket is connected to port = " << port );
+ SG_LOG( SG_IO, SG_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,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: bidirection mode not available for UDP sockets." );
return false;
}
if ( sock < 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Error opening socket: " << hostname
+ SG_LOG( SG_IO, SG_ALERT, "Error opening socket: " << hostname
<< ":" << port );
return false;
}
}
if ( result != length ) {
- FG_LOG( FG_IO, FG_INFO,
+ SG_LOG( SG_IO, SG_INFO,
"Warning: read() not enough bytes." );
}
}
// could cause problems so if you see connections
// dropping for unexplained reasons, LOOK HERE!
if ( result == 0 && save_len == 0 && first_read == true ) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Connection closed by foreign host." );
closesocket(sock);
open( get_dir() );
bool error_condition = false;
if ( writesocket(sock, buf, length) < 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Error writing to socket: " << port );
+ SG_LOG( SG_IO, SG_ALERT, "Error writing to socket: " << port );
error_condition = true;
}
if ( FD_ISSET(sock, &ready) ) {
int msgsock = accept(sock, 0, 0);
if ( msgsock < 0 ) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error: accept() failed in write()" );
return 0;
} else {
}
}
- FG_LOG( FG_IO, FG_INFO, "Client connections = " <<
+ SG_LOG( SG_IO, SG_INFO, "Client connections = " <<
client_connections.size() );
for ( int i = 0; i < (int)client_connections.size(); ++i ) {
int msgsock = client_connections[i];
// write the interesting data to the socket
if ( writesocket(msgsock, buf, length) == SOCKET_ERROR ) {
- FG_LOG( FG_IO, FG_ALERT, "Error writing to socket: " << port );
+ SG_LOG( SG_IO, SG_ALERT, "Error writing to socket: " << port );
error_condition = true;
} else {
#ifdef _POSIX_SYNCHRONIZED_IO
u_long arg = 1;
if (ioctlsocket( sock, FIONBIO, &arg ) != 0) {
int error_code = WSAGetLastError();
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Error " << error_code << ": unable to set non-blocking mode"
);
return false;
int err = WSAStartup( wVersionRequested, &wsaData );
if (err != 0)
{
- FG_LOG( FG_IO, FG_ALERT, "Error: Couldn't load winsock" );
+ SG_LOG( SG_IO, SG_ALERT, "Error: Couldn't load winsock" );
return false;
}
#if 0
if ( LOBYTE( wsaData.wVersion ) != 2 ||
HIBYTE( wsaData.wVersion ) != 2 ) {
- FG_LOG( FG_IO, FG_ALERT, "Couldn't load a suitable winsock");
+ SG_LOG( SG_IO, SG_ALERT, "Couldn't load a suitable winsock");
WSACleanup( );
return false;
}
// Constructor -- loads the interpolation table from the specified
// file
SGInterpTable::SGInterpTable( const string& file ) {
- FG_LOG( FG_MATH, FG_INFO, "Initializing Interpolator for " << file );
+ SG_LOG( SG_MATH, SG_INFO, "Initializing Interpolator for " << file );
fg_gzifstream in( file );
if ( !in.is_open() ) {
- FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << file );
+ SG_LOG( SG_GENERAL, SG_ALERT, "Cannot open file: " << file );
exit(-1);
}
in >> skipws;
size++;
} else {
- FG_LOG( FG_MATH, FG_ALERT,
+ SG_LOG( SG_MATH, SG_ALERT,
"fgInterpolateInit(): Exceed max table size = "
<< MAX_TABLE_SIZE );
exit(-1);
// printf ("i = %d ", i);
if ( (i == 0) && (x < table[0][0]) ) {
- FG_LOG( FG_MATH, FG_DEBUG,
+ SG_LOG( SG_MATH, SG_DEBUG,
"interpolate(): lookup error, x to small = " << x );
return table[0][1];
}
// cout << " table[size-1][0] = " << table[size-1][0] << endl;
if ( x > table[size-1][0] ) {
- FG_LOG( FG_MATH, FG_DEBUG,
+ SG_LOG( SG_MATH, SG_DEBUG,
"interpolate(): lookup error, x to big = " << x );
return table[size-1][1];
}
#ifdef DOMAIN_ERR_DEBUG
if ( errno ) {
perror("fgGeocToGeod()");
- FG_LOG( FG_GENERAL, FG_ALERT, "sqrt(" << t_lat*t_lat + E*E << ")" );
+ SG_LOG( SG_GENERAL, SG_ALERT, "sqrt(" << t_lat*t_lat + E*E << ")" );
}
#endif
// cout << " x_alpha = " << x_alpha << endl;
#ifdef DOMAIN_ERR_DEBUG
if ( errno ) {
perror("fgGeocToGeod()");
- FG_LOG( FG_GENERAL, FG_ALERT, "sqrt(" << SG_EQ_RAD_SQUARE_M - x_alpha * x_alpha
+ SG_LOG( SG_GENERAL, SG_ALERT, "sqrt(" << SG_EQ_RAD_SQUARE_M - x_alpha * x_alpha
<< ")" );
}
#endif
#ifdef DOMAIN_ERR_DEBUG
if ( errno ) {
perror("fgGeocToGeod()");
- FG_LOG( FG_GENERAL, FG_ALERT, "sqrt(" <<
+ SG_LOG( SG_GENERAL, SG_ALERT, "sqrt(" <<
1-EPS*EPS*sin_mu_a*sin_mu_a << ")" );
}
#endif
#ifdef DOMAIN_ERR_DEBUG
if ( errno ) {
perror("fgGeocToGeod()");
- FG_LOG( FG_GENERAL, FG_ALERT, "sqrt(" <<
+ SG_LOG( SG_GENERAL, SG_ALERT, "sqrt(" <<
SG_EQ_RAD_SQUARE_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)
<< ")" );
}
#ifdef DOMAIN_ERR_DEBUG
if ( errno ) {
perror("fgGeodToGeoc()");
- FG_LOG( FG_GENERAL, FG_ALERT, "sqrt(" <<
+ SG_LOG( SG_GENERAL, SG_ALERT, "sqrt(" <<
SG_EQ_RAD_SQUARE_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)
<< ")" );
}
if (_level == 0) {
if (string(name) != "PropertyList") {
- FG_LOG(FG_INPUT, FG_ALERT, "Root element name is " <<
+ SG_LOG(SG_INPUT, SG_ALERT, "Root element name is " <<
name << "; expected PropertyList");
_ok = false;
}
const char * att_alias = atts.getValue("alias");
if (att_alias != 0) {
if (!node->alias(att_alias))
- FG_LOG(FG_INPUT, FG_ALERT, "Failed to set alias to " << att_alias);
+ SG_LOG(SG_INPUT, SG_ALERT, "Failed to set alias to " << att_alias);
}
// Check for an include.
cerr << "Dir is " << FGPath(_base).dir() << endl;
path.append(att_include);
if (!readProperties(path.str(), node)) {
- FG_LOG(FG_INPUT, FG_ALERT, "Failed to read include file "
+ SG_LOG(SG_INPUT, SG_ALERT, "Failed to read include file "
<< att_include);
_ok = false;
}
} else if (st.type == "unknown") {
ret = st.node->setUnknownValue(_data);
} else {
- FG_LOG(FG_INPUT, FG_ALERT, "Unknown data type " << st.type
+ SG_LOG(SG_INPUT, SG_ALERT, "Unknown data type " << st.type
<< " assuming 'unknown'");
ret = st.node->setUnknownValue(_data);
}
if (!ret)
- FG_LOG(FG_INPUT, FG_ALERT, "readProperties: Failed to set "
+ SG_LOG(SG_INPUT, SG_ALERT, "readProperties: Failed to set "
<< st.node->getPath() << " to value \""
<< _data << "\" with type " << st.type);
}
void
PropsVisitor::warning (const char * message, int line, int column)
{
- FG_LOG(FG_INPUT, FG_ALERT, "readProperties: warning: "
+ SG_LOG(SG_INPUT, SG_ALERT, "readProperties: warning: "
<< message << " at line " << line << ", column " << column);
}
void
PropsVisitor::error (const char * message, int line, int column)
{
- FG_LOG(FG_INPUT, FG_ALERT, "readProperties: FATAL: " <<
+ SG_LOG(SG_INPUT, SG_ALERT, "readProperties: FATAL: " <<
message << " at line " << line << ", column " << column);
_ok = false;
}
if (input.good()) {
return readProperties(input, start_node, file);
} else {
- FG_LOG(FG_INPUT, FG_ALERT, "Error reading property list from file "
+ SG_LOG(SG_INPUT, SG_ALERT, "Error reading property list from file "
<< file);
return false;
}
if (output.good()) {
return writeProperties(output, start_node);
} else {
- FG_LOG(FG_INPUT, FG_ALERT, "Cannot write properties to file "
+ SG_LOG(SG_INPUT, SG_ALERT, "Cannot write properties to file "
<< file);
return false;
}
0,
NULL );
- FG_LOG( FG_IO, FG_ALERT, "Error opening serial device \""
+ SG_LOG( SG_IO, SG_ALERT, "Error opening serial device \""
<< device << "\" " << (const char*) lpMsgBuf );
LocalFree( lpMsgBuf );
return false;
cout << "Serial fd created = " << fd << endl;
if ( fd == -1 ) {
- FG_LOG( FG_IO, FG_ALERT, "Cannot open " << device
+ SG_LOG( SG_IO, SG_ALERT, "Cannot open " << device
<< " for serial I/O" );
return false;
} else {
// set required port parameters
if ( tcgetattr( fd, &config ) != 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Unable to poll port settings" );
+ SG_LOG( SG_IO, SG_ALERT, "Unable to poll port settings" );
return false;
}
// cout << "config.c_iflag = " << config.c_iflag << endl;
if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Unable to update port settings" );
+ SG_LOG( SG_IO, SG_ALERT, "Unable to update port settings" );
return false;
}
speed_t speed = B9600;
if ( tcgetattr( fd, &config ) != 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Unable to poll port settings" );
+ SG_LOG( SG_IO, SG_ALERT, "Unable to poll port settings" );
return false;
}
speed = B230400;
#endif
} else {
- FG_LOG( FG_IO, FG_ALERT, "Unsupported baud rate " << baud );
+ SG_LOG( SG_IO, SG_ALERT, "Unsupported baud rate " << baud );
return false;
}
if ( cfsetispeed( &config, speed ) != 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Problem setting input baud rate" );
+ SG_LOG( SG_IO, SG_ALERT, "Problem setting input baud rate" );
return false;
}
if ( cfsetospeed( &config, speed ) != 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Problem setting output baud rate" );
+ SG_LOG( SG_IO, SG_ALERT, "Problem setting output baud rate" );
return false;
}
if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) {
- FG_LOG( FG_IO, FG_ALERT, "Unable to update port settings" );
+ SG_LOG( SG_IO, SG_ALERT, "Unable to update port settings" );
return false;
}
if ( count < 0 ) {
// error condition
if ( errno != EAGAIN ) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Serial I/O on read, error number = " << errno );
}
if ( count < 0 ) {
// error condition
if ( errno != EAGAIN ) {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Serial I/O on read, error number = " << errno );
}
0,
NULL );
- FG_LOG( FG_IO, FG_ALERT, "Serial I/O write error: "
+ SG_LOG( SG_IO, SG_ALERT, "Serial I/O write error: "
<< (const char*) lpMsgBuf );
LocalFree( lpMsgBuf );
return int(lpNumberOfBytesWritten);
int count;
if ( error ) {
- FG_LOG( FG_IO, FG_ALERT, "attempting serial write error recovery" );
+ SG_LOG( SG_IO, SG_ALERT, "attempting serial write error recovery" );
// attempt some sort of error recovery
count = write(fd, "\n", 1);
if ( count == 1 ) {
error = false;
} else {
error = true;
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Serial I/O on write, error number = " << errno );
}
}
0,
NULL );
- FG_LOG( FG_IO, FG_ALERT, "Serial I/O write error: "
+ SG_LOG( SG_IO, SG_ALERT, "Serial I/O write error: "
<< (const char*) lpMsgBuf );
LocalFree( lpMsgBuf );
return int(lpNumberOfBytesWritten);
// ok ... in our context we don't really care if we can't
// write a string, we'll just get it the next time around
} else {
- FG_LOG( FG_IO, FG_ALERT,
+ SG_LOG( SG_IO, SG_ALERT,
"Serial I/O on write, error number = " << errno );
}
}
string value;
bool result;
- fglog().setLogLevels( FG_ALL, FG_INFO );
+ sglog().setLogLevels( SG_ALL, SG_INFO );
cout << "start of main" << endl;
SGTime::SGTime( double lon, double lat, const string& root )
{
- FG_LOG( FG_EVENT, FG_INFO, "Initializing Time" );
+ SG_LOG( SG_EVENT, SG_INFO, "Initializing Time" );
gst_diff = -9999.0;
if ( root != (string)"" ) {
FGPath zone( root );
zone.append( "zone.tab" );
- FG_LOG( FG_EVENT, FG_DEBUG, "Reading timezone info from: "
+ SG_LOG( SG_EVENT, SG_DEBUG, "Reading timezone info from: "
<< zone.str() );
tzContainer = new TimezoneContainer( zone.c_str() );
now = cur_time;
start_gmt = sgTimeGetGMT(gmt->tm_year, 2, 21, 12, 0, 0);
- FG_LOG( FG_EVENT, FG_DEBUG, " COURSE: GMT = "
+ SG_LOG( SG_EVENT, SG_DEBUG, " COURSE: GMT = "
<< sgTimeFormatTime(gmt, tbuf) );
- FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (GMT) = " << start_gmt );
+ SG_LOG( SG_EVENT, SG_DEBUG, " March 21 noon (GMT) = " << start_gmt );
diff = (now - start_gmt) / (3600.0 * 24.0);
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
" Time since 3/21/" << gmt->tm_year << " GMT = " << diff );
part = fmod(diff, 1.0);
lstTmp += 24.0;
}
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
" days = " << days << " hours = " << hours << " lon = "
<< lng << " lst = " << lstTmp );
void SGTime::update( double lon, double lat, long int warp ) {
double gst_precise, gst_course;
- FG_LOG( FG_EVENT, FG_DEBUG, "Updating time" );
+ SG_LOG( SG_EVENT, SG_DEBUG, "Updating time" );
// get current Unix calendar time (in seconds)
// warp += warp_delta;
cur_time = time(NULL) + warp;
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
" Current Unix calendar time = " << cur_time
<< " warp = " << warp );
// get GMT break down for current time
gmt = gmtime(&cur_time);
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
" Current GMT = " << gmt->tm_mon+1 << "/"
<< gmt->tm_mday << "/" << gmt->tm_year << " "
<< gmt->tm_hour << ":" << gmt->tm_min << ":"
// convert "back" to Julian date + partial day (as a fraction of one)
jd = mjd + MJD0;
- FG_LOG( FG_EVENT, FG_DEBUG, " Current Julian Date = " << jd );
+ SG_LOG( SG_EVENT, SG_DEBUG, " Current Julian Date = " << jd );
// printf(" Current Longitude = %.3f\n", FG_Longitude * SGD_RADIANS_TO_DEGREES);
if ( gst_diff < -100.0 ) {
// first time through do the expensive calculation & cheap
// calculation to get the difference.
- FG_LOG( FG_EVENT, FG_INFO, " First time, doing precise gst" );
+ SG_LOG( SG_EVENT, SG_INFO, " First time, doing precise gst" );
gst_precise = gst = sidereal_precise( mjd, 0.00 );
gst_course = sidereal_course( cur_time, gmt, 0.00 );
lst = sidereal_course( cur_time, gmt, -(lon * SGD_RADIANS_TO_DEGREES) ) + gst_diff;
}
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
" Current lon=0.00 Sidereal Time = " << gst );
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
" Current LOCAL Sidereal Time = " << lst << " ("
<< sidereal_precise( mjd, -(lon * SGD_RADIANS_TO_DEGREES) )
<< ") (diff = " << gst_diff << ")" );
x /= 3600.0;
gst = (1.0/SIDRATE)*hr + x;
- FG_LOG( FG_EVENT, FG_DEBUG, " gst => " << gst );
+ SG_LOG( SG_EVENT, SG_DEBUG, " gst => " << gst );
return gst;
}
time_t start = mktime(&mt);
- FG_LOG( FG_EVENT, FG_DEBUG, "start1 = " << start );
+ SG_LOG( SG_EVENT, SG_DEBUG, "start1 = " << start );
// the ctime() call can screw up time progression on some versions
// of Linux
- // fgPrintf( FG_EVENT, FG_DEBUG, "start2 = %s", ctime(&start));
- FG_LOG( FG_EVENT, FG_DEBUG, "(tm_isdst = " << mt.tm_isdst << ")" );
+ // fgPrintf( SG_EVENT, SG_DEBUG, "start2 = %s", ctime(&start));
+ SG_LOG( SG_EVENT, SG_DEBUG, "(tm_isdst = " << mt.tm_isdst << ")" );
timezone = fix_up_timezone( timezone );
# if defined( TIMEZONE_OFFSET_WORKS )
- FG_LOG( FG_EVENT, FG_DEBUG,
+ SG_LOG( SG_EVENT, SG_DEBUG,
"start = " << start << ", timezone = " << timezone );
return( start - timezone );
# else // ! defined( TIMEZONE_OFFSET_WORKS )
if ( daylight > 0 ) {
daylight = 1;
} else if ( daylight < 0 ) {
- FG_LOG( FG_EVENT, FG_WARN,
+ SG_LOG( SG_EVENT, FG_WARN,
"OOOPS, problem in sg_time.cxx, no daylight savings info." );
}
long int offset = -(timezone / 3600 - daylight);
- FG_LOG( FG_EVENT, FG_DEBUG, " Raw time zone offset = " << timezone );
- FG_LOG( FG_EVENT, FG_DEBUG, " Daylight Savings = " << daylight );
- FG_LOG( FG_EVENT, FG_DEBUG, " Local hours from GMT = " << offset );
+ SG_LOG( SG_EVENT, SG_DEBUG, " Raw time zone offset = " << timezone );
+ SG_LOG( SG_EVENT, SG_DEBUG, " Daylight Savings = " << daylight );
+ SG_LOG( SG_EVENT, SG_DEBUG, " Local hours from GMT = " << offset );
long int start_gmt = start - timezone + (daylight * 3600);
- FG_LOG( FG_EVENT, FG_DEBUG, " March 21 noon (CST) = " << start );
+ SG_LOG( SG_EVENT, SG_DEBUG, " March 21 noon (CST) = " << start );
return ( start_gmt );
# endif // ! defined( TIMEZONE_OFFSET_WORKS )