1 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
7 ------------- Copyright (C) 2001 Jon S. Berndt (jsb@hal-pc.org) -------------
9 This program is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free Software
11 Foundation; either version 2 of the License, or (at your option) any later
14 This program is distributed in the hope that it will be useful, but WITHOUT
15 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16 FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
19 You should have received a copy of the GNU General Public License along with
20 this program; if not, write to the Free Software Foundation, Inc., 59 Temple
21 Place - Suite 330, Boston, MA 02111-1307, USA.
23 Further information about the GNU General Public License can also be found on
24 the world wide web at http://www.gnu.org.
27 --------------------------------------------------------------------------------
30 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
32 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
37 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
39 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
44 # include <simgear/compiler.h>
52 # include <simgear/constants.h>
60 # if defined(sgi) && !defined(__GNUC__)
69 # define M_PI 3.14159265358979323846
74 #if !defined(WIN32) || defined(__GNUC__)
78 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
80 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
82 #define ID_JSBBASE "$Id$"
84 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
86 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
90 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
92 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
94 /** JSBSim Base class.
99 /*%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
101 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%*/
105 /// Constructor for FGJSBBase.
108 /// Destructor for FGJSBBase.
111 /// JSBSim Message structure
114 unsigned int messageId;
117 enum mType {eText, eInteger, eDouble, eBool} type;
123 ///@name JSBSim console output highlighting terms.
126 static char highint[5];
127 /// low intensity text
128 static char halfint[5];
129 /// normal intensity text
130 static char normint[6];
131 /// resets text properties
132 static char reset[5];
134 static char underon[5];
136 static char underoff[6];
138 static char fgblue[6];
140 static char fgcyan[6];
142 static char fgred[6];
144 static char fggreen[6];
146 static char fgdef[6];
149 ///@name JSBSim Messaging functions
151 /** Places a Message structure on the Message queue.
152 @param msg pointer to a Message structure
153 @return pointer to a Message structure */
154 Message* PutMessage(Message* msg);
155 /** Creates a message with the given text and places it on the queue.
156 @param text message text
157 @return pointer to a Message structure */
158 Message* PutMessage(const string& text);
159 /** Creates a message with the given text and boolean value and places it on the queue.
160 @param text message text
161 @param bVal boolean value associated with the message
162 @return pointer to a Message structure */
163 Message* PutMessage(const string& text, bool bVal);
164 /** Creates a message with the given text and integer value and places it on the queue.
165 @param text message text
166 @param iVal integer value associated with the message
167 @return pointer to a Message structure */
168 Message* PutMessage(const string& text, int iVal);
169 /** Creates a message with the given text and double value and places it on the queue.
170 @param text message text
171 @param dVal double value associated with the message
172 @return pointer to a Message structure */
173 Message* PutMessage(const string& text, double dVal);
174 /** Reads the message on the queue (but does not delete it).
175 @return pointer to a Message structure (or NULL if no mesage) */
176 Message* ReadMessage(void);
177 /** Reads the message on the queue and removes it from the queue.
178 @return pointer to a Message structure (or NULL if no mesage) */
179 Message* ProcessMessage(void);
181 string GetVersion(void) {return JSBSim_version;}
183 void disableHighLighting(void);
185 static short debug_lvl;
186 static double KelvinToFahrenheit (double kelvin) {
187 return 1.8*kelvin - 459.4;
190 static double RankineToCelsius (double rankine) {
191 return (rankine - 491.67)/1.8;
194 static double FahrenheitToCelsius (double fahrenheit) {
195 return (fahrenheit - 32.0)/1.8;
198 static double CelsiusToFahrenheit (double celsius) {
199 return celsius * 1.8 + 32.0;
202 /** Finite precision comparison.
203 @param a first value to compare
204 @param b second value to compare
205 @return if the two values can be considered equal up to roundoff */
206 static bool EqualToRoundoff(double a, double b) {
207 double eps = 2.0*DBL_EPSILON;
208 return fabs(a - b) <= eps*max(fabs(a), fabs(b));
211 /** Finite precision comparison.
212 @param a first value to compare
213 @param b second value to compare
214 @return if the two values can be considered equal up to roundoff */
215 static bool EqualToRoundoff(float a, float b) {
216 float eps = 2.0*FLT_EPSILON;
217 return fabs(a - b) <= eps*max(fabs(a), fabs(b));
220 /** Finite precision comparison.
221 @param a first value to compare
222 @param b second value to compare
223 @return if the two values can be considered equal up to roundoff */
224 static bool EqualToRoundoff(float a, double b) {
225 return EqualToRoundoff(a, (float)b);
228 /** Finite precision comparison.
229 @param a first value to compare
230 @param b second value to compare
231 @return if the two values can be considered equal up to roundoff */
232 static bool EqualToRoundoff(double a, float b) {
233 return EqualToRoundoff((float)a, b);
237 static Message localMsg;
239 static std::queue <Message*> Messages;
241 void Debug(int from) {};
243 static unsigned int frame;
244 static unsigned int messageId;
246 static const double radtodeg;
247 static const double degtorad;
248 static const double hptoftlbssec;
249 static const double psftoinhg;
250 static const double fpstokts;
251 static const double ktstofps;
252 static const double inchtoft;
253 static const double in3tom3;
254 static double Reng; // Specific Gas Constant,ft^2/(sec^2*R)
255 static const double SHRatio;
256 static const double lbtoslug;
257 static const double slugtolb;
258 static const string needed_cfg_version;
259 static const string JSBSim_version;
263 enum {eL = 1, eM, eN };
265 enum {eP = 1, eQ, eR };
266 /// Velocities U, V, W
267 enum {eU = 1, eV, eW };
268 /// Positions X, Y, Z
269 enum {eX = 1, eY, eZ };
270 /// Euler angles Phi, Theta, Psi
271 enum {ePhi = 1, eTht, ePsi };
272 /// Stability axis forces, Drag, Side force, Lift
273 enum {eDrag = 1, eSide, eLift };
274 /// Local frame orientation Roll, Pitch, Yaw
275 enum {eRoll = 1, ePitch, eYaw };
276 /// Local frame position North, East, Down
277 enum {eNorth = 1, eEast, eDown };
278 /// Locations Radius, Latitude, Longitude
279 enum {eLat = 1, eLong, eRad };
280 /// Conversion specifiers
281 enum {inNone = 0, inDegrees, inRadians, inMeters, inFeet };
284 //%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%