From 6816ecb3eabdba7cef4df46db357a58603824cdd Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 6 Nov 1998 21:17:23 +0000 Subject: [PATCH 01/16] Converted to new logstream debugging facility. This allows release builds with no messages at all (and no performance impact) by using the -DFG_NDEBUG flag. --- Debug/Makefile.am | 8 ++++++- Debug/fg_debug.h | 1 + Math/fg_random.c | 13 ++++++---- Math/interpolater.cxx | 55 ++++++++++++++++++++++--------------------- Math/interpolater.hxx | 10 +++++++- Misc/zfstream.hxx | 19 +++++---------- 6 files changed, 60 insertions(+), 46 deletions(-) diff --git a/Debug/Makefile.am b/Debug/Makefile.am index ab447e4cd..f45c0bde7 100644 --- a/Debug/Makefile.am +++ b/Debug/Makefile.am @@ -1,5 +1,11 @@ +EXTRA_DIST = logtest.cxx + noinst_LIBRARIES = libDebug.a -libDebug_a_SOURCES = fg_debug.c fg_debug.h +libDebug_a_SOURCES = \ + debug_types.h \ + logstream.cxx logstream.hxx + +# fg_debug.c fg_debug.h \ INCLUDES += -I$(top_builddir) diff --git a/Debug/fg_debug.h b/Debug/fg_debug.h index 5a818697a..22adb912a 100644 --- a/Debug/fg_debug.h +++ b/Debug/fg_debug.h @@ -23,6 +23,7 @@ * (Log is kept at end of this file) **************************************************************************/ +#error "use logstream" #ifndef _FG_DEBUG_H #define _FG_DEBUG_H diff --git a/Math/fg_random.c b/Math/fg_random.c index 476e71992..1f6ad2cb6 100644 --- a/Math/fg_random.c +++ b/Math/fg_random.c @@ -32,7 +32,7 @@ #include /* for random(), srandom() */ #include /* for time() to seed srandom() */ -#include +/* #include */ #include "fg_random.h" @@ -54,7 +54,7 @@ /* Seed the random number generater with time() so we don't see the * same sequence every time */ void fg_srandom(void) { - fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); + /* fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); */ #ifdef HAVE_RAND srand(time(NULL)); @@ -75,9 +75,14 @@ double fg_random(void) { /* $Log$ -/* Revision 1.8 1998/04/25 22:06:23 curt -/* Edited cvs log messages in source files ... bad bad bad! +/* Revision 1.9 1998/11/06 21:17:26 curt +/* Converted to new logstream debugging facility. This allows release +/* builds with no messages at all (and no performance impact) by using +/* the -DFG_NDEBUG flag. /* + * Revision 1.8 1998/04/25 22:06:23 curt + * Edited cvs log messages in source files ... bad bad bad! + * * Revision 1.7 1998/04/24 00:43:13 curt * Wrapped "#include " in "#ifdef HAVE_CONFIG_H" * diff --git a/Math/interpolater.cxx b/Math/interpolater.cxx index c77529e55..394de5a8d 100644 --- a/Math/interpolater.cxx +++ b/Math/interpolater.cxx @@ -24,45 +24,41 @@ // (Log is kept at end of this file) -#include +#include -#include +#include #include +#include #include "interpolater.hxx" // Constructor -- loads the interpolation table from the specified // file -fgINTERPTABLE::fgINTERPTABLE( char *file ) { - char fgfile[256], line[256]; - fgFile fd; - - fgPrintf( FG_MATH, FG_INFO, "Initializing Interpolator for %s\n", file); - - // First try "file.gz" - strcpy(fgfile, file); - strcat(fgfile, ".gz"); - if ( (fd = fgopen(fgfile, "rb")) == NULL ) { - // Next try "path" - if ( (fd = fgopen(file, "rb")) == NULL ) { - fgPrintf(FG_MATH, FG_EXIT, "Cannot open file: %s\n", file); - } +fgINTERPTABLE::fgINTERPTABLE( const string& file ) { + string fgfile, line; + + FG_LOG( FG_MATH, FG_INFO, "Initializing Interpolator for " << file ); + + fg_gzifstream in( file ); + if ( !in ) { + FG_LOG( FG_GENERAL, FG_ALERT, "Cannot open file: " << file ); + exit(-1); } size = 0; - while ( fggets(fd, line, 250) != NULL ) { + in >> skipcomment; + while ( ! in.eof() ){ if ( size < MAX_TABLE_SIZE ) { - sscanf(line, "%lf %lf\n", &(table[size][0]), &(table[size][1])); + in >> table[size][0] >> table[size][1]; size++; } else { - fgPrintf( FG_MATH, FG_EXIT, - "fgInterpolateInit(): Exceed max table size = %d\n", - MAX_TABLE_SIZE ); + FG_LOG( FG_MATH, FG_ALERT, + "fgInterpolateInit(): Exceed max table size = " + << MAX_TABLE_SIZE ); + exit(-1); } } - - fgclose(fd); } @@ -80,14 +76,14 @@ double fgINTERPTABLE::interpolate(double x) { // printf ("i = %d ", i); if ( (i == 0) && (x < table[0][0]) ) { - fgPrintf( FG_MATH, FG_ALERT, - "fgInterpolateInit(): lookup error, x to small = %.2f\n", x); + FG_LOG( FG_MATH, FG_ALERT, + "fgInterpolateInit(): lookup error, x to small = " << x ); return(0.0); } if ( x > table[i][0] ) { - fgPrintf( FG_MATH, FG_ALERT, - "fgInterpolateInit(): lookup error, x to big = %.2f\n", x); + FG_LOG( FG_MATH, FG_ALERT, + "fgInterpolateInit(): lookup error, x to big = " << x ); return(0.0); } @@ -107,6 +103,11 @@ fgINTERPTABLE::~fgINTERPTABLE( void ) { // $Log$ +// Revision 1.5 1998/11/06 21:17:27 curt +// Converted to new logstream debugging facility. This allows release +// builds with no messages at all (and no performance impact) by using +// the -DFG_NDEBUG flag. +// // Revision 1.4 1998/05/13 18:24:25 curt // Wrapped zlib calls so zlib can be optionally disabled. // diff --git a/Math/interpolater.hxx b/Math/interpolater.hxx index 92a8a0319..9a7c0bd32 100644 --- a/Math/interpolater.hxx +++ b/Math/interpolater.hxx @@ -33,6 +33,9 @@ #endif +#include + + #define MAX_TABLE_SIZE 32 @@ -44,7 +47,7 @@ public: // Constructor -- loads the interpolation table from the specified // file - fgINTERPTABLE( char *file ); + fgINTERPTABLE( const string& file ); // Given an x value, linearly interpolate the y value from the table double interpolate(double x); @@ -58,6 +61,11 @@ public: // $Log$ +// Revision 1.3 1998/11/06 21:17:28 curt +// Converted to new logstream debugging facility. This allows release +// builds with no messages at all (and no performance impact) by using +// the -DFG_NDEBUG flag. +// // Revision 1.2 1998/04/22 13:18:10 curt // C++ - ified comments. Make file open errors fatal. // diff --git a/Misc/zfstream.hxx b/Misc/zfstream.hxx index b5567273c..8374575e9 100644 --- a/Misc/zfstream.hxx +++ b/Misc/zfstream.hxx @@ -65,19 +65,7 @@ # define ios_badbit ios::badbit # define ios_failbit ios::failbit -// Dummy up some char traits for now. -template struct char_traits{}; - -FG_TEMPLATE_NULL -struct char_traits -{ - typedef char char_type; - typedef int int_type; - typedef streampos pos_type; - typedef streamoff off_type; - - static int_type eof() { return EOF; } -}; +# include "Include/fg_traits.hxx" #endif // FG_HAVE_STD_INCLUDES @@ -154,6 +142,11 @@ struct gzifstream_base #endif // _zfstream_hxx // $Log$ +// Revision 1.5 1998/11/06 21:17:29 curt +// Converted to new logstream debugging facility. This allows release +// builds with no messages at all (and no performance impact) by using +// the -DFG_NDEBUG flag. +// // Revision 1.4 1998/11/06 14:05:16 curt // More portability improvements by Bernie Bright. // -- 2.39.5 From 4fb45c478392ff43c167d1c87269516130f43cdf Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 6 Nov 1998 21:20:41 +0000 Subject: [PATCH 02/16] Initial revision. --- Debug/debug_types.h | 35 ++++++++ Debug/logstream.cxx | 68 +++++++++++++++ Debug/logstream.hxx | 195 ++++++++++++++++++++++++++++++++++++++++++++ Debug/logtest.cxx | 34 ++++++++ 4 files changed, 332 insertions(+) create mode 100644 Debug/debug_types.h create mode 100644 Debug/logstream.cxx create mode 100644 Debug/logstream.hxx create mode 100644 Debug/logtest.cxx diff --git a/Debug/debug_types.h b/Debug/debug_types.h new file mode 100644 index 000000000..65e6fe912 --- /dev/null +++ b/Debug/debug_types.h @@ -0,0 +1,35 @@ +// NB: To add a dbg_class, add it here, and add it to the structure in +// fg_debug.c + +typedef enum { + FG_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_UNDEFD = 0x00001000, // For range checking + + FG_ALL = 0xFFFFFFFF +} fgDebugClass; + + +// NB: To add a priority, add it here. +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; + diff --git a/Debug/logstream.cxx b/Debug/logstream.cxx new file mode 100644 index 000000000..708bd660a --- /dev/null +++ b/Debug/logstream.cxx @@ -0,0 +1,68 @@ +// Stream based logging mechanism. +// +// Written by Bernie Bright, 1998 +// +// Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + +#include "logstream.hxx" + +bool logbuf::logging_enabled = true; +fgDebugClass logbuf::logClass = FG_NONE; +fgDebugPriority logbuf::logPriority = FG_INFO; +streambuf* logbuf::sbuf = NULL; + +logbuf::logbuf() +{ +// if ( sbuf == NULL ) +// sbuf = cerr.rdbuf(); +} + +logbuf::~logbuf() +{ + if ( sbuf ) + sbuf->sync(); +} + +void +logbuf::set_sb( streambuf* sb ) +{ + if ( sbuf ) + sbuf->sync(); + + sbuf = sb; +} + +void +logbuf::set_log_level( fgDebugClass c, fgDebugPriority p ) +{ + logClass = c; + logPriority = p; +} + +void +logstream::setLogLevels( fgDebugClass c, fgDebugPriority p ) +{ + logbuf::set_log_level( c, p ); +} + +// $Log$ +// Revision 1.1 1998/11/06 21:20:41 curt +// Initial revision. +// diff --git a/Debug/logstream.hxx b/Debug/logstream.hxx new file mode 100644 index 000000000..5c51aa530 --- /dev/null +++ b/Debug/logstream.hxx @@ -0,0 +1,195 @@ +// Stream based logging mechanism. +// +// Written by Bernie Bright, 1998 +// +// Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + +#ifndef _LOGSTREAM_H +#define _LOGSTREAM_H + +#include "Include/compiler.h" + +#ifdef FG_HAVE_STD_INCLUDES +# include +# include +#else +# include +# include "Include/fg_traits.hxx" +#endif + +#include "debug_types.h" + +// +// TODO: +// +// 1. Change output destination. Done. +// 2. Make logbuf thread safe. +// 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. +// +class logbuf : public streambuf +{ +public: + +#ifndef FG_HAVE_STD_INCLUDES + typedef char_traits traits_type; + typedef char_traits::int_type int_type; + typedef char_traits::pos_type pos_type; + typedef char_traits::off_type off_type; +#endif +// logbuf( streambuf* sb ) : sbuf(sb) {} + logbuf(); + ~logbuf(); + + // 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 global logging level. + static void set_log_level( fgDebugClass c, fgDebugPriority p ); + + // + void set_sb( streambuf* sb ); + +protected: + + int sync() { return sbuf->sync(); } + int_type overflow( int ch ); +// int xsputn( const char* s, istreamsize n ); + +private: + + // The streambuf used for actual output. Defaults to cerr.rdbuf(). + static streambuf* sbuf; + + static bool logging_enabled; + static fgDebugClass logClass; + static fgDebugPriority logPriority; + +private: + + // Not defined. + logbuf( const logbuf& ); + void operator= ( const logbuf& ); +}; + +inline void +logbuf::set_log_state( fgDebugClass c, fgDebugPriority p ) +{ + logging_enabled = ((c & logClass) != 0 && p >= logPriority); +} + +inline logbuf::int_type +logbuf::overflow( int c ) +{ + return logging_enabled ? sbuf->sputc(c) : (EOF == 0 ? 1: 0); +} + +//----------------------------------------------------------------------------- +// +// logstream manipulator for setting the log level of a message. +// +struct loglevel +{ + loglevel( fgDebugClass c, fgDebugPriority p ) + : logClass(c), logPriority(p) {} + + fgDebugClass logClass; + fgDebugPriority 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. +// +struct logstream_base +{ +// logstream_base( streambuf* sb ) : lbuf(sb) {} + logstream_base() {} + + logbuf lbuf; +}; + +//----------------------------------------------------------------------------- +// +// +// +class logstream : private logstream_base, public ostream +{ +public: + // The default is to send messages to cerr. + logstream( ostream& out ) +// : logstream_base(out.rdbuf()), + : logstream_base(), + ostream(&lbuf) { lbuf.set_sb(out.rdbuf());} + + void set_output( ostream& out ) { lbuf.set_sb( out.rdbuf() ); } + + // Set the global log class and priority level. + void setLogLevels( fgDebugClass c, fgDebugPriority p ); + + // Output operator to capture the debug level and priority of a message. + inline ostream& operator<< ( const loglevel& l ); +}; + +inline ostream& +logstream::operator<< ( const loglevel& l ) +{ + lbuf.set_log_state( l.logClass, l.logPriority ); + 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. +// +inline logstream& +fglog() +{ + static logstream logstrm( cerr ); + return logstrm; +} + +#ifdef FG_NDEBUG +# define FG_LOG(C,P,M) +#else +# define FG_LOG(C,P,M) fglog() << loglevel(C,P) << M << endl +#endif + +#endif // _LOGSTREAM_H + +// $Log$ +// Revision 1.1 1998/11/06 21:20:42 curt +// Initial revision. +// diff --git a/Debug/logtest.cxx b/Debug/logtest.cxx new file mode 100644 index 000000000..b02c6b086 --- /dev/null +++ b/Debug/logtest.cxx @@ -0,0 +1,34 @@ +#include +#include "Debug/logstream.hxx" + +int +main( int argc, char* argv[] ) +{ + fglog().setLogLevels( FG_ALL, FG_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" ); + + int i = 12345; + long l = 54321L; + double d = 3.14159; + string s = "Hello world!"; + + FG_LOG( FG_EVENT, FG_INFO, "event::info " + << "i=" << i + << ", l=" << l + << ", d=" << d + << ", d*l=" << d*l + << ", s=\"" << s << "\"" ); + + // This shouldn't appear in log output: + FG_LOG( FG_EVENT, FG_DEBUG, "event::debug " + << "- this should be seen - " + << "d=" << d + << ", s=\"" << s << "\"" ); + + return 0; +} -- 2.39.5 From 74d314558c83435920faf76c9827626897a29b76 Mon Sep 17 00:00:00 2001 From: curt Date: Sat, 7 Nov 1998 19:07:02 +0000 Subject: [PATCH 03/16] Enable release builds using the --without-logging option to the configure script. Also a couple log message cleanups, plus some C to C++ comment conversion. --- Debug/logstream.hxx | 10 ++++ Math/fg_random.c | 140 ++++++++++++++++++++++---------------------- Math/fg_random.h | 92 +++++++++++++++-------------- 3 files changed, 127 insertions(+), 115 deletions(-) diff --git a/Debug/logstream.hxx b/Debug/logstream.hxx index 5c51aa530..c9ce10b67 100644 --- a/Debug/logstream.hxx +++ b/Debug/logstream.hxx @@ -24,6 +24,11 @@ #ifndef _LOGSTREAM_H #define _LOGSTREAM_H +#ifdef HAVE_CONFIG_H +# include +#endif + + #include "Include/compiler.h" #ifdef FG_HAVE_STD_INCLUDES @@ -190,6 +195,11 @@ fglog() #endif // _LOGSTREAM_H // $Log$ +// Revision 1.2 1998/11/07 19:07:02 curt +// Enable release builds using the --without-logging option to the configure +// script. Also a couple log message cleanups, plus some C to C++ comment +// conversion. +// // Revision 1.1 1998/11/06 21:20:42 curt // Initial revision. // diff --git a/Math/fg_random.c b/Math/fg_random.c index 1f6ad2cb6..31b24be7d 100644 --- a/Math/fg_random.c +++ b/Math/fg_random.c @@ -1,27 +1,25 @@ -/************************************************************************** - * fg_random.c -- routines to handle random number generation - * - * Written by Curtis Olson, started July 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * (Log is kept at end of this file) - **************************************************************************/ +// fg_random.c -- routines to handle random number generation +// +// Written by Curtis Olson, started July 1997. +// +// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) #ifdef HAVE_CONFIG_H @@ -29,10 +27,8 @@ #endif #include -#include /* for random(), srandom() */ -#include /* for time() to seed srandom() */ - -/* #include */ +#include // for random(), srandom() +#include // for time() to seed srandom() #include "fg_random.h" @@ -51,10 +47,10 @@ #endif -/* Seed the random number generater with time() so we don't see the - * same sequence every time */ +// Seed the random number generater with time() so we don't see the +// same sequence every time void fg_srandom(void) { - /* fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); */ + // fgPrintf( FG_MATH, FG_INFO, "Seeding random number generater\n"); #ifdef HAVE_RAND srand(time(NULL)); @@ -64,7 +60,7 @@ void fg_srandom(void) { } -/* return a random number between [0.0, 1.0) */ +// return a random number between [0.0, 1.0) double fg_random(void) { #ifdef HAVE_RAND return(rand() / (double)RAND_MAX); @@ -74,41 +70,45 @@ double fg_random(void) { } -/* $Log$ -/* Revision 1.9 1998/11/06 21:17:26 curt -/* Converted to new logstream debugging facility. This allows release -/* builds with no messages at all (and no performance impact) by using -/* the -DFG_NDEBUG flag. -/* - * Revision 1.8 1998/04/25 22:06:23 curt - * Edited cvs log messages in source files ... bad bad bad! - * - * Revision 1.7 1998/04/24 00:43:13 curt - * Wrapped "#include " in "#ifdef HAVE_CONFIG_H" - * - * Revision 1.6 1998/04/18 03:53:42 curt - * Miscellaneous Tweaks. - * - * Revision 1.5 1998/04/03 22:10:29 curt - * Converting to Gnu autoconf system. - * - * Revision 1.4 1998/02/03 23:20:28 curt - * Lots of little tweaks to fix various consistency problems discovered by - * Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper - * passed arguments along to the real printf(). Also incorporated HUD changes - * by Michele America. - * - * Revision 1.3 1998/01/27 00:47:59 curt - * Incorporated Paul Bleisch's new debug message - * system and commandline/config file processing code. - * - * Revision 1.2 1997/12/30 20:47:48 curt - * Integrated new event manager with subsystem initializations. - * - * Revision 1.1 1997/07/30 16:04:09 curt - * Moved random routines from Utils/ to Math/ - * - * Revision 1.1 1997/07/19 22:31:57 curt - * Initial revision. - * - */ +// $Log$ +// Revision 1.10 1998/11/07 19:07:03 curt +// Enable release builds using the --without-logging option to the configure +// script. Also a couple log message cleanups, plus some C to C++ comment +// conversion. +// +// Revision 1.9 1998/11/06 21:17:26 curt +// Converted to new logstream debugging facility. This allows release +// builds with no messages at all (and no performance impact) by using +// the -DFG_NDEBUG flag. +// +// Revision 1.8 1998/04/25 22:06:23 curt +// Edited cvs log messages in source files ... bad bad bad! +// +// Revision 1.7 1998/04/24 00:43:13 curt +// Wrapped "#include " in "#ifdef HAVE_CONFIG_H" +// +// Revision 1.6 1998/04/18 03:53:42 curt +// Miscellaneous Tweaks. +// +// Revision 1.5 1998/04/03 22:10:29 curt +// Converting to Gnu autoconf system. +// +// Revision 1.4 1998/02/03 23:20:28 curt +// Lots of little tweaks to fix various consistency problems discovered by +// Solaris' CC. Fixed a bug in fg_debug.c with how the fgPrintf() wrapper +// passed arguments along to the real printf(). Also incorporated HUD changes +// by Michele America. +// +// Revision 1.3 1998/01/27 00:47:59 curt +// Incorporated Paul Bleisch's new debug message +// system and commandline/config file processing code. +// +// Revision 1.2 1997/12/30 20:47:48 curt +// Integrated new event manager with subsystem initializations. +// +// Revision 1.1 1997/07/30 16:04:09 curt +// Moved random routines from Utils/ to Math/ +// +// Revision 1.1 1997/07/19 22:31:57 curt +// Initial revision. +// diff --git a/Math/fg_random.h b/Math/fg_random.h index 845a7f369..3ae53a053 100644 --- a/Math/fg_random.h +++ b/Math/fg_random.h @@ -1,27 +1,25 @@ -/************************************************************************** - * fg_random.h -- routines to handle random number generation - * - * Written by Curtis Olson, started July 1997. - * - * Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com - * - * 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., 675 Mass Ave, Cambridge, MA 02139, USA. - * - * $Id$ - * (Log is kept at end of this file) - **************************************************************************/ +// fg_random.h -- routines to handle random number generation +// +// Written by Curtis Olson, started July 1997. +// +// Copyright (C) 1997 Curtis L. Olson - curt@infoplane.com +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) #ifndef _FG_RANDOM_H @@ -33,11 +31,11 @@ extern "C" { #endif -/* Seed the random number generater with time() so we don't see the - * same sequence every time */ +// Seed the random number generater with time() so we don't see the +// same sequence every time void fg_srandom(void); -/* return a random number between [0.0, 1.0) */ +// return a random number between [0.0, 1.0) double fg_random(void); @@ -46,23 +44,27 @@ double fg_random(void); #endif -#endif /* _FG_RANDOM_H */ +#endif // _FG_RANDOM_H -/* $Log$ -/* Revision 1.3 1998/04/21 17:03:48 curt -/* Prepairing for C++ integration. -/* - * Revision 1.2 1998/01/22 02:59:38 curt - * Changed #ifdef FILE_H to #ifdef _FILE_H - * - * Revision 1.1 1997/07/30 16:04:09 curt - * Moved random routines from Utils/ to Math/ - * - * Revision 1.2 1997/07/23 21:52:28 curt - * Put comments around the text after an #endif for increased portability. - * - * Revision 1.1 1997/07/19 22:31:57 curt - * Initial revision. - * - */ +// $Log$ +// Revision 1.4 1998/11/07 19:07:04 curt +// Enable release builds using the --without-logging option to the configure +// script. Also a couple log message cleanups, plus some C to C++ comment +// conversion. +// +// Revision 1.3 1998/04/21 17:03:48 curt +// Prepairing for C++ integration. +// +// Revision 1.2 1998/01/22 02:59:38 curt +// Changed #ifdef FILE_H to #ifdef _FILE_H +// +// Revision 1.1 1997/07/30 16:04:09 curt +// Moved random routines from Utils/ to Math/ +// +// Revision 1.2 1997/07/23 21:52:28 curt +// Put comments around the text after an #endif for increased portability. +// +// Revision 1.1 1997/07/19 22:31:57 curt +// Initial revision. +// -- 2.39.5 From 0fec7b25991ab49140632e23399048a31f6e060b Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 9 Nov 1998 23:42:12 +0000 Subject: [PATCH 04/16] Initial revision. --- Bucket/bucketutils.hxx | 76 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 Bucket/bucketutils.hxx diff --git a/Bucket/bucketutils.hxx b/Bucket/bucketutils.hxx new file mode 100644 index 000000000..3145871ef --- /dev/null +++ b/Bucket/bucketutils.hxx @@ -0,0 +1,76 @@ +/************************************************************************** + * bucketutils.hxx -- support routines to handle fgBUCKET operations + * + * Written by Bernie Bright, started January 1998. + * + * Copyright (C) 1998 Bernie Bright - bbright@c031.aone.net.au + * + * 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., 675 Mass Ave, Cambridge, MA 02139, USA. + * + * $Id$ + * (Log is kept at end of this file) + **************************************************************************/ + + +#ifndef _BUCKETUTILS_HXX +#define _BUCKETUTILS_HXX + +#include + +#include "bucketutils.h" + +#include +FG_USING_STD(string); + +inline bool +operator== ( const fgBUCKET& b1, const fgBUCKET& b2 ) +{ + return ( b1.lon == b2.lon && + b1.lat == b2.lat && + b1.x == b2.x && + b1.y == b2.y ); +} + +inline string +fgBucketGenIndex( const fgBUCKET& p ) +{ + char index_str[256]; + sprintf( index_str, "%ld", fgBucketGenIndex( &p ) ); + return string( index_str ); +} + +inline string +fgBucketGenBasePath( const fgBUCKET& p ) +{ + char base_path[256]; + fgBucketGenBasePath( &p, base_path ); + return string( base_path ); +} + +inline ostream& +operator<< ( ostream& out, const fgBUCKET& b ) +{ + return out << b.lon << "," << b.lat << " " << b.x << "," << b.y; +} + +#endif /* _BUCKETUTILS_HXX */ + + +// $Log$ +// Revision 1.1 1998/11/09 23:42:12 curt +// Initial revision. +// + + -- 2.39.5 From 2091bf21447bceb2a769f1da7f2368ed56486bbf Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 11 Nov 1998 00:18:36 +0000 Subject: [PATCH 05/16] Check for domain error in fgGeoctoGeod() --- Math/fg_geodesy.cxx | 21 +++++++++++++++++++++ Math/point3d.hxx | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Math/fg_geodesy.cxx b/Math/fg_geodesy.cxx index cbc249415..ac7fa9bb9 100644 --- a/Math/fg_geodesy.cxx +++ b/Math/fg_geodesy.cxx @@ -10,6 +10,7 @@ #include +#include #include #include @@ -54,6 +55,13 @@ void fgGeocToGeod( double lat_geoc, double radius, double r_alpha = x_alpha/cos(lat_geoc); l_point = radius - r_alpha; *alt = l_point*cos(delt_lambda); + + // check for domain error + if ( errno == EDOM ) { + cout << "Domain ERROR in fgGeocToGeod!!!!\n"; + *alt = 0.0; + } + denom = sqrt(1-EPS*EPS*sin_mu_a*sin_mu_a); rho_alpha = EQUATORIAL_RADIUS_M*(1-EPS)/ (denom*denom*denom); @@ -63,7 +71,14 @@ void fgGeocToGeod( double lat_geoc, double radius, double sin_lambda_sl = sin( lambda_sl ); *sea_level_r = sqrt(RESQ_M / (1 + ((1/(E*E))-1)*sin_lambda_sl*sin_lambda_sl)); + + // check for domain error + if ( errno == EDOM ) { + cout << "Domain ERROR in fgGeocToGeod!!!!\n"; + *sea_level_r = 0.0; + } } + } @@ -139,6 +154,9 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, $Header$ $Log$ +Revision 1.3 1998/11/11 00:18:36 curt +Check for domain error in fgGeoctoGeod() + Revision 1.2 1998/10/16 23:36:36 curt c++-ifying. @@ -218,6 +236,9 @@ Initial Flight Gear revision. // $Log$ +// Revision 1.3 1998/11/11 00:18:36 curt +// Check for domain error in fgGeoctoGeod() +// // Revision 1.2 1998/10/16 23:36:36 curt // c++-ifying. // diff --git a/Math/point3d.hxx b/Math/point3d.hxx index a3c9eea31..ba43a8c07 100644 --- a/Math/point3d.hxx +++ b/Math/point3d.hxx @@ -133,7 +133,7 @@ operator >> ( istream& in, Point3D& p) inline ostream& operator<< ( ostream& out, const Point3D& p ) { - return out << p.n[PX] << ',' << p.n[PY] << ',' << p.n[PZ]; + return out << p.n[PX] << ", " << p.n[PY] << ", " << p.n[PZ]; } /////////////////////////// @@ -293,6 +293,9 @@ Point3D::distance3D(const Point3D& a ) const // $Log$ +// Revision 1.4 1998/11/11 00:18:38 curt +// Check for domain error in fgGeoctoGeod() +// // Revision 1.3 1998/10/20 18:21:49 curt // Tweaks from Bernie Bright. // -- 2.39.5 From 0b7d4c8c1e9f93eb6d4ad15945e74db39897ba0a Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 16 Nov 1998 13:53:01 +0000 Subject: [PATCH 06/16] Initial revision. --- Serial/Makefile.am | 13 ++++ Serial/serial.cxx | 162 ++++++++++++++++++++++++++++++++++++++++++ Serial/serial.hxx | 71 ++++++++++++++++++ Serial/testserial.cxx | 17 +++++ 4 files changed, 263 insertions(+) create mode 100644 Serial/Makefile.am create mode 100644 Serial/serial.cxx create mode 100644 Serial/serial.hxx create mode 100644 Serial/testserial.cxx diff --git a/Serial/Makefile.am b/Serial/Makefile.am new file mode 100644 index 000000000..66a9f1662 --- /dev/null +++ b/Serial/Makefile.am @@ -0,0 +1,13 @@ +bin_PROGRAMS = testserial + +noinst_LIBRARIES = libSerial.a + +libSerial_a_SOURCES = serial.cxx serial.hxx + +testserial_SOURCES = testserial.cxx + +testserial_LDADD = \ + $(top_builddir)/Lib/Serial/libSerial.a \ + $(top_builddir)/Lib/Debug/libDebug.a + +INCLUDES += -I$(top_builddir) -I$(top_builddir)/Lib diff --git a/Serial/serial.cxx b/Serial/serial.cxx new file mode 100644 index 000000000..0106e242c --- /dev/null +++ b/Serial/serial.cxx @@ -0,0 +1,162 @@ +// serial.cxx -- Unix serial I/O support +// +// Written by Curtis Olson, started November 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#include +#include +#include +#include +#include + +#include + +#include "serial.hxx" + + +fgSERIAL::fgSERIAL() { + dev_open = false; +} + +fgSERIAL::fgSERIAL(const string& device, int baud) { + open_port(device); + + if ( dev_open ) { + set_baud(baud); + } +} + +fgSERIAL::~fgSERIAL() { + close(fd); +} + +bool fgSERIAL::open_port(const string& device) { + if ( (fd = open(device.c_str(), O_RDWR | O_NONBLOCK)) == -1 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Cannot open " << device + << " for serial I/O" ); + return false; + } else { + dev_open = true; + return true; + } +} + +bool fgSERIAL::set_baud(int baud) { + struct termios config; + speed_t speed; + + cout << "attempting to set baud rate to: " << baud << endl; + + if ( tcgetattr( fd, &config ) != 0 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Unable to poll port settings" ); + return false; + } + + if ( baud == 300 ) { + speed = B300; + } else if ( baud == 1200 ) { + speed = B1200; + } else if ( baud == 2400 ) { + speed = B2400; + } else if ( baud == 4800 ) { + speed = B4800; + } else if ( baud == 9600 ) { + speed = B9600; + } else if ( baud == 19200 ) { + speed = B19200; + } else if ( baud == 38400 ) { + speed = B38400; + } else if ( baud == 57600 ) { + speed = B57600; + } else if ( baud == 115200 ) { + speed = B115200; + } else if ( baud == 230400 ) { + speed = B230400; + } else { + FG_LOG( FG_SERIAL, FG_ALERT, "Unsupported baud rate " << baud ); + return false; + } + + if ( cfsetispeed( &config, speed ) != 0 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Problem setting input baud rate" ); + return false; + } + + if ( cfsetospeed( &config, speed ) != 0 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Problem setting output baud rate" ); + return false; + } + + if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Unable to update port settings" ); + return false; + } + + cout << "successfully set baud to " << baud << endl; + + return true; +} + +string fgSERIAL::read_port() { + const int max_count = 1024; + char buffer[max_count+1]; + int count; + string result; + + count = read(fd, buffer, max_count); + // cout << "read " << count << " bytes" << endl; + + if ( count < 0 ) { + // error condition + if ( errno != EAGAIN ) { + FG_LOG( FG_SERIAL, FG_ALERT, + "Serial I/O on read, error number = " << errno ); + } + + return ""; + } else { + buffer[count] = '\0'; + result = buffer; + + return result; + } +} + +int fgSERIAL::write_port(const string& value) { + int count; + + count = write(fd, value.c_str(), value.length()); + // cout << "write '" << value << "' " << count << " bytes" << endl; + + if ( (int)count != (int)value.length() ) { + FG_LOG( FG_SERIAL, FG_ALERT, + "Serial I/O on write, error number = " << errno ); + } + + return count; +} + + +// $Log$ +// Revision 1.1 1998/11/16 13:53:02 curt +// Initial revision. +// diff --git a/Serial/serial.hxx b/Serial/serial.hxx new file mode 100644 index 000000000..011e49596 --- /dev/null +++ b/Serial/serial.hxx @@ -0,0 +1,71 @@ +// serial.hxx -- Unix serial I/O support +// +// Written by Curtis Olson, started November 1998. +// +// Copyright (C) 1998 Curtis L. Olson - curt@flightgear.org +// +// 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., 675 Mass Ave, Cambridge, MA 02139, USA. +// +// $Id$ +// (Log is kept at end of this file) + + +#ifndef _SERIAL_HXX +#define _SERIAL_HXX + + +#ifndef __cplusplus +# error This library requires C++ +#endif + + +#include + +// if someone know how to do this all with C++ streams let me know +#include + + +class fgSERIAL +{ + +private: + + int fd; + bool dev_open; + +public: + + fgSERIAL(); + fgSERIAL(const string& device, int baud); + + ~fgSERIAL(); + + bool open_port(const string& device); + bool close_port(); + bool set_baud(int baud); + string read_port(); + int write_port(const string& value); + + inline bool is_enabled() { return dev_open; } +}; + + +#endif // _SERIAL_HXX + + +// $Log$ +// Revision 1.1 1998/11/16 13:53:02 curt +// Initial revision. +// diff --git a/Serial/testserial.cxx b/Serial/testserial.cxx new file mode 100644 index 000000000..b563ac76a --- /dev/null +++ b/Serial/testserial.cxx @@ -0,0 +1,17 @@ +#include + +#include "serial.hxx" + +main () { + fgSERIAL port( "/dev/ttyS1", 4800); + string value; + + port.write_port("ATDT 626-9800\n"); + + while ( true ) { + value = port.read_port(); + if ( value.length() ) { + cout << "-> " << value << endl; + } + } +} -- 2.39.5 From 54352225f1e5a1fcfc021ba0181b292eecd2c2d5 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 16 Nov 1998 13:56:45 +0000 Subject: [PATCH 07/16] Added the Serial subdirectory --- Lib/Makefile.am | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/Lib/Makefile.am b/Lib/Makefile.am index 73035a69e..36d5ced41 100644 --- a/Lib/Makefile.am +++ b/Lib/Makefile.am @@ -4,4 +4,21 @@ else AUDIO_DIRS = endif -SUBDIRS = $(AUDIO_DIRS) Bucket Debug DEM gpc Math Misc PUI XGL zlib +if ENABLE_UNIX_SERIAL +SERIAL_DIRS = Serial +else +SERIAL_DIRS = +endif + +SUBDIRS = \ + $(AUDIO_DIRS) \ + Bucket \ + Debug \ + DEM \ + gpc \ + Math \ + Misc \ + PUI \ + $(SERIAL_DIRS) \ + XGL\ + zlib -- 2.39.5 From a878570a8d52fa71e38beeb8727922d481ff4b83 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 16 Nov 1998 13:57:04 +0000 Subject: [PATCH 08/16] Added an FG_SERIAL type to the FG_LOG macro. --- Debug/debug_types.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Debug/debug_types.h b/Debug/debug_types.h index 65e6fe912..0d9c209a6 100644 --- a/Debug/debug_types.h +++ b/Debug/debug_types.h @@ -16,7 +16,8 @@ typedef enum { FG_EVENT = 0x00000200, FG_AIRCRAFT = 0x00000400, FG_AUTOPILOT = 0x00000800, - FG_UNDEFD = 0x00001000, // For range checking + FG_SERIAL = 0x00001000, + FG_UNDEFD = 0x00002000, // For range checking FG_ALL = 0xFFFFFFFF } fgDebugClass; -- 2.39.5 From aa02e72829421c4f479401690767dabf4a455928 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 19 Nov 1998 03:35:43 +0000 Subject: [PATCH 09/16] Updates ... --- Serial/serial.cxx | 26 +++++++++++++++++++++----- Serial/testserial.cxx | 15 ++++++++++++++- 2 files changed, 35 insertions(+), 6 deletions(-) diff --git a/Serial/serial.cxx b/Serial/serial.cxx index 0106e242c..9c9106b59 100644 --- a/Serial/serial.cxx +++ b/Serial/serial.cxx @@ -50,22 +50,37 @@ fgSERIAL::~fgSERIAL() { } bool fgSERIAL::open_port(const string& device) { + struct termios config; + if ( (fd = open(device.c_str(), O_RDWR | O_NONBLOCK)) == -1 ) { FG_LOG( FG_SERIAL, FG_ALERT, "Cannot open " << device << " for serial I/O" ); return false; } else { dev_open = true; - return true; } + + // set software flow control + if ( tcgetattr( fd, &config ) != 0 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Unable to poll port settings" ); + return false; + } + + config.c_iflag |= IXON; + config.c_iflag |= IXOFF; + + if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) { + FG_LOG( FG_SERIAL, FG_ALERT, "Unable to update port settings" ); + return false; + } + + return true; } bool fgSERIAL::set_baud(int baud) { struct termios config; speed_t speed; - cout << "attempting to set baud rate to: " << baud << endl; - if ( tcgetattr( fd, &config ) != 0 ) { FG_LOG( FG_SERIAL, FG_ALERT, "Unable to poll port settings" ); return false; @@ -111,8 +126,6 @@ bool fgSERIAL::set_baud(int baud) { return false; } - cout << "successfully set baud to " << baud << endl; - return true; } @@ -157,6 +170,9 @@ int fgSERIAL::write_port(const string& value) { // $Log$ +// Revision 1.2 1998/11/19 03:35:43 curt +// Updates ... +// // Revision 1.1 1998/11/16 13:53:02 curt // Initial revision. // diff --git a/Serial/testserial.cxx b/Serial/testserial.cxx index b563ac76a..c582c13c3 100644 --- a/Serial/testserial.cxx +++ b/Serial/testserial.cxx @@ -1,10 +1,23 @@ #include +#include + #include "serial.hxx" main () { - fgSERIAL port( "/dev/ttyS1", 4800); + fgSERIAL port; string value; + bool result; + + fglog().setLogLevels( FG_ALL, FG_INFO ); + + cout << "start of main" << endl; + + result = port.open_port("/dev/ttyS1"); + cout << "opened port, result = " << result << endl; + + result = port.set_baud(4800); + cout << "set baud, result = " << result << endl; port.write_port("ATDT 626-9800\n"); -- 2.39.5 From d56289f897617f2542d1e87971b645525c5da333 Mon Sep 17 00:00:00 2001 From: curt Date: Thu, 19 Nov 1998 13:52:54 +0000 Subject: [PATCH 10/16] port configuration tweaks & experiments. --- Serial/serial.cxx | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/Serial/serial.cxx b/Serial/serial.cxx index 9c9106b59..18173b43e 100644 --- a/Serial/serial.cxx +++ b/Serial/serial.cxx @@ -60,14 +60,24 @@ bool fgSERIAL::open_port(const string& device) { dev_open = true; } - // set software flow control + // set required port parameters if ( tcgetattr( fd, &config ) != 0 ) { FG_LOG( FG_SERIAL, FG_ALERT, "Unable to poll port settings" ); return false; } - config.c_iflag |= IXON; - config.c_iflag |= IXOFF; + cfmakeraw( &config ); + + // cout << "config.c_iflag = " << config.c_iflag << endl; + + // software flow control on + // config.c_iflag |= IXON; + // config.c_iflag |= IXOFF; + + // disable hardware flow control + // config.c_cflag |= CRTSCTS; + + // cout << "config.c_iflag = " << config.c_iflag << endl; if ( tcsetattr( fd, TCSANOW, &config ) != 0 ) { FG_LOG( FG_SERIAL, FG_ALERT, "Unable to update port settings" ); @@ -170,6 +180,9 @@ int fgSERIAL::write_port(const string& value) { // $Log$ +// Revision 1.3 1998/11/19 13:52:54 curt +// port configuration tweaks & experiments. +// // Revision 1.2 1998/11/19 03:35:43 curt // Updates ... // -- 2.39.5 From 62ca2e02270de2c4359c82ff751cd733332422c5 Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 20 Nov 1998 00:59:23 +0000 Subject: [PATCH 11/16] FreeBSD support. --- Misc/stopwatch.hxx | 8 ++++++++ src/slPortability.h | 2 +- 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/Misc/stopwatch.hxx b/Misc/stopwatch.hxx index e4034ac88..d3bcfade4 100644 --- a/Misc/stopwatch.hxx +++ b/Misc/stopwatch.hxx @@ -25,6 +25,9 @@ * *************************************************************************** * $Log$ + * Revision 1.3 1998/11/20 01:01:03 curt + * FreeBSD support. + * * Revision 1.2 1998/11/02 18:28:31 curt * Additional win32 support. * @@ -66,7 +69,12 @@ #endif // WIN32 #if defined( HAVE_GETRUSAGE ) +# if defined( __FreeBSD__ ) +# include +# endif +# include # include +# include #elif defined( WIN32 ) # include #else diff --git a/src/slPortability.h b/src/slPortability.h index 88c1cbcc8..08d780c14 100644 --- a/src/slPortability.h +++ b/src/slPortability.h @@ -31,7 +31,7 @@ #include #include -#ifdef __linux__ +#if defined(__linux__) || defined(__FreeBSD__) #define SL_USING_OSS_AUDIO 1 #endif -- 2.39.5 From a644bd2b03169483da74f476b17a8fc41ad0d85c Mon Sep 17 00:00:00 2001 From: curt Date: Fri, 20 Nov 1998 01:00:36 +0000 Subject: [PATCH 12/16] Patch in fgGeoc2Geod() to avoid a floating explosion. point3d.hxx include math.h for FreeBSD --- Math/fg_geodesy.cxx | 12 +++++++++++- Math/point3d.hxx | 6 ++++++ 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/Math/fg_geodesy.cxx b/Math/fg_geodesy.cxx index ac7fa9bb9..b6d1a214d 100644 --- a/Math/fg_geodesy.cxx +++ b/Math/fg_geodesy.cxx @@ -48,7 +48,9 @@ void fgGeocToGeod( double lat_geoc, double radius, double } else { t_lat = tan(lat_geoc); x_alpha = E*EQUATORIAL_RADIUS_M/sqrt(t_lat*t_lat + E*E); - mu_alpha = atan2(sqrt(RESQ_M - x_alpha*x_alpha),E*x_alpha); + double tmp = RESQ_M - x_alpha * x_alpha; + if ( tmp < 0.0 ) { tmp = 0.0; } + mu_alpha = atan2(sqrt(tmp),E*x_alpha); if (lat_geoc < 0) mu_alpha = - mu_alpha; sin_mu_a = sin(mu_alpha); delt_lambda = mu_alpha - lat_geoc; @@ -154,6 +156,10 @@ void fgGeodToGeoc( double lat_geod, double alt, double *sl_radius, $Header$ $Log$ +Revision 1.4 1998/11/20 01:00:36 curt +Patch in fgGeoc2Geod() to avoid a floating explosion. +point3d.hxx include math.h for FreeBSD + Revision 1.3 1998/11/11 00:18:36 curt Check for domain error in fgGeoctoGeod() @@ -236,6 +242,10 @@ Initial Flight Gear revision. // $Log$ +// Revision 1.4 1998/11/20 01:00:36 curt +// Patch in fgGeoc2Geod() to avoid a floating explosion. +// point3d.hxx include math.h for FreeBSD +// // Revision 1.3 1998/11/11 00:18:36 curt // Check for domain error in fgGeoctoGeod() // diff --git a/Math/point3d.hxx b/Math/point3d.hxx index ba43a8c07..30054bd0f 100644 --- a/Math/point3d.hxx +++ b/Math/point3d.hxx @@ -33,6 +33,8 @@ #include #include +#include + const double fgPoint3_Epsilon = 0.0000001; @@ -293,6 +295,10 @@ Point3D::distance3D(const Point3D& a ) const // $Log$ +// Revision 1.5 1998/11/20 01:00:38 curt +// Patch in fgGeoc2Geod() to avoid a floating explosion. +// point3d.hxx include math.h for FreeBSD +// // Revision 1.4 1998/11/11 00:18:38 curt // Check for domain error in fgGeoctoGeod() // -- 2.39.5 From 1690f5475dda1243db39d157928adf7dbe521299 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 23 Nov 1998 21:46:13 +0000 Subject: [PATCH 13/16] Add bucketutils.hxx to source list. --- Bucket/Makefile.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Bucket/Makefile.am b/Bucket/Makefile.am index 089ddc8a2..6f7e25dd2 100644 --- a/Bucket/Makefile.am +++ b/Bucket/Makefile.am @@ -1,5 +1,5 @@ noinst_LIBRARIES = libBucket.a -libBucket_a_SOURCES = bucketutils.c bucketutils.h +libBucket_a_SOURCES = bucketutils.c bucketutils.h bucketutils.hxx INCLUDES += -I$(top_builddir) -- 2.39.5 From d7748704d77d31e76b3da3a1f95bd7bbab456377 Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 23 Nov 1998 21:46:36 +0000 Subject: [PATCH 14/16] Borland portability tweaks. --- Math/MAT3mat.c | 4 +++- Math/point3d.hxx | 10 ++++++++-- XGL/xglUtils.c | 6 ++++-- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/Math/MAT3mat.c b/Math/MAT3mat.c index 6eb74cb1c..9a1e7c991 100644 --- a/Math/MAT3mat.c +++ b/Math/MAT3mat.c @@ -11,7 +11,9 @@ #endif #ifdef WIN32 -# include /* required for memset() and memcpy() */ +# ifndef HAVE_STL_SGI_PORT +# include /* required for memset() and memcpy() */ +# endif #endif #include diff --git a/Math/point3d.hxx b/Math/point3d.hxx index 30054bd0f..299f71e87 100644 --- a/Math/point3d.hxx +++ b/Math/point3d.hxx @@ -33,8 +33,11 @@ #include #include -#include - +#if defined( __BORLANDC__ ) +# define exception c_exception +#elif defined( __FreeBSD__ ) +# include +#endif const double fgPoint3_Epsilon = 0.0000001; @@ -295,6 +298,9 @@ Point3D::distance3D(const Point3D& a ) const // $Log$ +// Revision 1.6 1998/11/23 21:46:37 curt +// Borland portability tweaks. +// // Revision 1.5 1998/11/20 01:00:38 curt // Patch in fgGeoc2Geod() to avoid a floating explosion. // point3d.hxx include math.h for FreeBSD diff --git a/XGL/xglUtils.c b/XGL/xglUtils.c index bc5d7217e..971c353b4 100644 --- a/XGL/xglUtils.c +++ b/XGL/xglUtils.c @@ -5,16 +5,18 @@ #include #include +#include #if !defined( __CYGWIN__ ) && !defined( __CYGWIN32__ ) -# include +# if !defined( HAVE_STL_SGI_PORT ) // Avoid malloc with STLport +# include +# endif #endif #ifdef HAVE_UNISTD_H # include #endif -#include #include "xgl.h" -- 2.39.5 From 3730ce404fb280af6b35be478f47b3a97d7d2f0b Mon Sep 17 00:00:00 2001 From: curt Date: Mon, 23 Nov 1998 21:47:00 +0000 Subject: [PATCH 15/16] Cygnus tools compatibility tweaks. --- Serial/serial.cxx | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Serial/serial.cxx b/Serial/serial.cxx index 18173b43e..e866f8f9d 100644 --- a/Serial/serial.cxx +++ b/Serial/serial.cxx @@ -22,6 +22,7 @@ // (Log is kept at end of this file) +#include #include #include #include @@ -89,7 +90,7 @@ bool fgSERIAL::open_port(const string& device) { bool fgSERIAL::set_baud(int baud) { struct termios config; - speed_t speed; + speed_t speed = B9600; if ( tcgetattr( fd, &config ) != 0 ) { FG_LOG( FG_SERIAL, FG_ALERT, "Unable to poll port settings" ); @@ -114,8 +115,10 @@ bool fgSERIAL::set_baud(int baud) { speed = B57600; } else if ( baud == 115200 ) { speed = B115200; +#if defined( linux ) || defined( __FreeBSD__ ) } else if ( baud == 230400 ) { speed = B230400; +#endif } else { FG_LOG( FG_SERIAL, FG_ALERT, "Unsupported baud rate " << baud ); return false; @@ -180,6 +183,9 @@ int fgSERIAL::write_port(const string& value) { // $Log$ +// Revision 1.4 1998/11/23 21:47:00 curt +// Cygnus tools compatibility tweaks. +// // Revision 1.3 1998/11/19 13:52:54 curt // port configuration tweaks & experiments. // -- 2.39.5 From b82aef65e5e2d3c8c7cbd258e286a2dd46fca8d3 Mon Sep 17 00:00:00 2001 From: curt Date: Wed, 25 Nov 1998 01:33:23 +0000 Subject: [PATCH 16/16] Remove call to cfmakeraw() --- Serial/serial.cxx | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Serial/serial.cxx b/Serial/serial.cxx index e866f8f9d..175c3b241 100644 --- a/Serial/serial.cxx +++ b/Serial/serial.cxx @@ -67,7 +67,7 @@ bool fgSERIAL::open_port(const string& device) { return false; } - cfmakeraw( &config ); + // cfmakeraw( &config ); // cout << "config.c_iflag = " << config.c_iflag << endl; @@ -183,6 +183,9 @@ int fgSERIAL::write_port(const string& value) { // $Log$ +// Revision 1.5 1998/11/25 01:33:23 curt +// Remove call to cfmakeraw() +// // Revision 1.4 1998/11/23 21:47:00 curt // Cygnus tools compatibility tweaks. // -- 2.39.5