1
0
Fork 0
flightgear/src/Network/garmin.cxx

421 lines
10 KiB
C++
Raw Normal View History

1999-11-19 02:10:24 +00:00
// garmin.cxx -- Garmin protocal class
//
// Written by Curtis Olson, started November 1999.
//
// Copyright (C) 1999 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$
2000-02-16 23:01:03 +00:00
#include <simgear/debug/logstream.hxx>
2000-09-27 20:16:22 +00:00
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
2000-02-15 03:30:01 +00:00
1999-11-19 02:10:24 +00:00
#include <FDM/flight.hxx>
2000-07-07 20:28:51 +00:00
#include <Main/globals.hxx>
1999-11-19 02:10:24 +00:00
#include "garmin.hxx"
SG_USING_NAMESPACE(std);
1999-11-19 02:10:24 +00:00
FGGarmin::FGGarmin() {
}
FGGarmin::~FGGarmin() {
}
// calculate the garmin check sum
static char calc_nmea_cksum(char *sentence) {
unsigned char sum = 0;
int i, len;
// cout << sentence << endl;
len = strlen(sentence);
sum = sentence[0];
for ( i = 1; i < len; i++ ) {
// cout << sentence[i];
sum ^= sentence[i];
}
// cout << endl;
// printf("sum = %02x\n", sum);
return sum;
}
// generate Garmin message
bool FGGarmin::gen_message() {
// cout << "generating garmin message" << endl;
char rmc[256], rmc_sum[256], rmz[256], rmz_sum[256];
char dir;
int deg;
double min;
2000-07-07 20:28:51 +00:00
SGTime *t = globals->get_time_params();
1999-11-19 02:10:24 +00:00
char utc[10];
sprintf( utc, "%02d%02d%02d",
t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
char lat[20];
2001-03-24 04:48:44 +00:00
double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
1999-11-19 02:10:24 +00:00
if ( latd < 0.0 ) {
latd *= -1.0;
dir = 'S';
} else {
dir = 'N';
}
deg = (int)(latd);
min = (latd - (double)deg) * 60.0;
sprintf( lat, "%02d%06.3f,%c", abs(deg), min, dir);
char lon[20];
2001-03-24 04:48:44 +00:00
double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
1999-11-19 02:10:24 +00:00
if ( lond < 0.0 ) {
lond *= -1.0;
dir = 'W';
} else {
dir = 'E';
}
deg = (int)(lond);
min = (lond - (double)deg) * 60.0;
sprintf( lon, "%03d%06.3f,%c", abs(deg), min, dir);
char speed[10];
sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
char heading[10];
2001-03-24 04:48:44 +00:00
sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
1999-11-19 02:10:24 +00:00
char altitude_m[10];
sprintf( altitude_m, "%02d",
2001-03-24 04:56:46 +00:00
(int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
1999-11-19 02:10:24 +00:00
char altitude_ft[10];
sprintf( altitude_ft, "%02d", (int)cur_fdm_state->get_Altitude() );
char date[10];
sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday,
t->getGmt()->tm_mon+1, t->getGmt()->tm_year );
// $GPRMC,HHMMSS,A,DDMM.MMM,N,DDDMM.MMM,W,XXX.X,XXX.X,DDMMYY,XXX.X,E*XX
sprintf( rmc, "GPRMC,%s,A,%s,%s,%s,%s,%s,000.0,E",
utc, lat, lon, speed, heading, date );
sprintf( rmc_sum, "%02X", calc_nmea_cksum(rmc) );
// sprintf( gga, "$GPGGA,%s,%s,%s,1,04,0.0,%s,M,00.0,M,,*00\r\n",
// utc, lat, lon, altitude_m );
sprintf( rmz, "PGRMZ,%s,f,3", altitude_ft );
sprintf( rmz_sum, "%02X", calc_nmea_cksum(rmz) );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_DEBUG, rmc );
SG_LOG( SG_IO, SG_DEBUG, rmz );
1999-11-19 02:10:24 +00:00
string garmin_sentence;
// RMC sentence
garmin_sentence = "$";
garmin_sentence += rmc;
garmin_sentence += "*";
garmin_sentence += rmc_sum;
garmin_sentence += "\n";
// RMZ sentence (garmin proprietary)
garmin_sentence += "$";
garmin_sentence += rmz;
garmin_sentence += "*";
garmin_sentence += rmz_sum;
garmin_sentence += "\n";
cout << garmin_sentence;
1999-11-19 02:10:24 +00:00
length = garmin_sentence.length();
strncpy( buf, garmin_sentence.c_str(), length );
return true;
}
// parse Garmin message
bool FGGarmin::parse_message() {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, "parse garmin message" );
1999-11-19 02:10:24 +00:00
string msg = buf;
msg = msg.substr( 0, length );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, "entire message = " << msg );
1999-11-19 02:10:24 +00:00
string::size_type begin_line, end_line, begin, end;
begin_line = begin = 0;
// extract out each line
end_line = msg.find("\n", begin_line);
while ( end_line != string::npos ) {
string line = msg.substr(begin_line, end_line - begin_line);
begin_line = end_line + 1;
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " input line = " << line );
1999-11-19 02:10:24 +00:00
// leading character
string start = msg.substr(begin, 1);
++begin;
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " start = " << start );
1999-11-19 02:10:24 +00:00
// sentence
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string sentence = msg.substr(begin, end - begin);
begin = end + 1;
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " sentence = " << sentence );
1999-11-19 02:10:24 +00:00
double lon_deg, lon_min, lat_deg, lat_min;
double lon, lat, speed, heading, altitude;
if ( sentence == "GPRMC" ) {
// time
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string utc = msg.substr(begin, end - begin);
begin = end + 1;
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " utc = " << utc );
1999-11-19 02:10:24 +00:00
// junk
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string junk = msg.substr(begin, end - begin);
begin = end + 1;
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
1999-11-19 02:10:24 +00:00
// lat val
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string lat_str = msg.substr(begin, end - begin);
begin = end + 1;
lat_deg = atof( lat_str.substr(0, 2).c_str() );
lat_min = atof( lat_str.substr(2).c_str() );
// lat dir
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string lat_dir = msg.substr(begin, end - begin);
begin = end + 1;
lat = lat_deg + ( lat_min / 60.0 );
if ( lat_dir == "S" ) {
lat *= -1;
}
2001-03-24 04:48:44 +00:00
cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
1999-11-19 02:10:24 +00:00
// lon val
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string lon_str = msg.substr(begin, end - begin);
begin = end + 1;
lon_deg = atof( lon_str.substr(0, 3).c_str() );
lon_min = atof( lon_str.substr(3).c_str() );
// lon dir
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string lon_dir = msg.substr(begin, end - begin);
begin = end + 1;
lon = lon_deg + ( lon_min / 60.0 );
if ( lon_dir == "W" ) {
lon *= -1;
}
2001-03-24 04:48:44 +00:00
cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
1999-11-19 02:10:24 +00:00
I tested: LaRCsim c172 on-ground and in-air starts, reset: all work UIUC Cessna172 on-ground and in-air starts work as expected, reset results in an aircraft that is upside down but does not crash FG. I don't know what it was like before, so it may well be no change. JSBSim c172 and X15 in-air starts work fine, resets now work (and are trimmed), on-ground starts do not -- the c172 ends up on its back. I suspect this is no worse than before. I did not test: Balloon (the weather code returns nan's for the atmosphere data --this is in the weather module and apparently is a linux only bug) ADA (don't know how) MagicCarpet (needs work yet) External (don't know how) known to be broken: LaRCsim c172 on-ground starts with a negative terrain altitude (this happens at KPAO when the scenery is not present). The FDM inits to about 50 feet AGL and the model falls to the ground. It does stay upright, however, and seems to be fine once it settles out, FWIW. To do: --implement set_Model on the bus --bring Christian's weather data into JSBSim -- add default method to bus for updating things like the sin and cos of latitude (for Balloon, MagicCarpet) -- lots of cleanup The files: src/FDM/flight.cxx src/FDM/flight.hxx -- all data members now declared protected instead of private. -- eliminated all but a small set of 'setters', no change to getters. -- that small set is declared virtual, the default implementation provided preserves the old behavior -- all of the vector data members are now initialized. -- added busdump() method -- FG_LOG's all the bus data when called, useful for diagnostics. src/FDM/ADA.cxx -- bus data members now directly assigned to src/FDM/Balloon.cxx -- bus data members now directly assigned to -- changed V_equiv_kts to V_calibrated_kts src/FDM/JSBSim.cxx src/FDM/JSBSim.hxx -- bus data members now directly assigned to -- implemented the FGInterface virtual setters with JSBSim specific logic -- changed the static FDMExec to a dynamic fdmex (needed so that the JSBSim object can be deleted when a model change is called for) -- implemented constructor and destructor, moved some of the logic formerly in init() to constructor -- added logic to bring up FGEngInterface objects and set the RPM and throttle values. src/FDM/LaRCsim.cxx src/FDM/LaRCsim.hxx -- bus data members now directly assigned to -- implemented the FGInterface virtual setters with LaRCsim specific logic, uses LaRCsimIC -- implemented constructor and destructor, moved some of the logic formerly in init() to constructor -- moved default inertias to here from fg_init.cxx -- eliminated the climb rate calculation. The equivalent, climb_rate = -1*vdown, is now in copy_from_LaRCsim(). src/FDM/LaRCsimIC.cxx src/FDM/LaRCsimIC.hxx -- similar to FGInitialCondition, this class has all the logic needed to turn data like Vc and Mach into the more fundamental quantities LaRCsim needs to initialize. -- put it in src/FDM since it is a class src/FDM/MagicCarpet.cxx -- bus data members now directly assigned to src/FDM/Makefile.am -- adds LaRCsimIC.hxx and cxx src/FDM/JSBSim/FGAtmosphere.h src/FDM/JSBSim/FGDefs.h src/FDM/JSBSim/FGInitialCondition.cpp src/FDM/JSBSim/FGInitialCondition.h src/FDM/JSBSim/JSBSim.cpp -- changes to accomodate the new bus src/FDM/LaRCsim/atmos_62.h src/FDM/LaRCsim/ls_geodesy.h -- surrounded prototypes with #ifdef __cplusplus ... #endif , functions here are needed in LaRCsimIC src/FDM/LaRCsim/c172_main.c src/FDM/LaRCsim/cherokee_aero.c src/FDM/LaRCsim/ls_aux.c src/FDM/LaRCsim/ls_constants.h src/FDM/LaRCsim/ls_geodesy.c src/FDM/LaRCsim/ls_geodesy.h src/FDM/LaRCsim/ls_step.c src/FDM/UIUCModel/uiuc_betaprobe.cpp -- changed PI to LS_PI, eliminates preprocessor naming conflict with weather module src/FDM/LaRCsim/ls_interface.c src/FDM/LaRCsim/ls_interface.h -- added function ls_set_model_dt() src/Main/bfi.cxx -- eliminated calls that set the NED speeds to body components. They are no longer needed and confuse the new bus. src/Main/fg_init.cxx -- eliminated calls that just brought the bus data up-to-date (e.g. set_sin_cos_latitude). or set default values. The bus now handles the defaults and updates itself when the setters are called (for LaRCsim and JSBSim). A default method for doing this needs to be added to the bus. -- added fgVelocityInit() to set the speed the user asked for. Both JSBSim and LaRCsim can now be initialized using any of: vc,mach, NED components, UVW components. src/Main/main.cxx --eliminated call to fgFDMSetGroundElevation, this data is now 'pulled' onto the bus every update() src/Main/options.cxx src/Main/options.hxx -- added enum to keep track of the speed requested by the user -- eliminated calls to set NED velocity properties to body speeds, they are no longer needed. -- added options for the NED components. src/Network/garmin.cxx src/Network/nmea.cxx --eliminated calls that just brought the bus data up-to-date (e.g. set_sin_cos_latitude). The bus now updates itself when the setters are called (for LaRCsim and JSBSim). A default method for doing this needs to be added to the bus. -- changed set_V_equiv_kts to set_V_calibrated_kts. set_V_equiv_kts no longer exists ( get_V_equiv_kts still does, though) src/WeatherCM/FGLocalWeatherDatabase.cpp -- commented out the code to put the weather data on the bus, a different scheme for this is needed.
2000-10-24 00:34:50 +00:00
#if 0
1999-11-19 02:10:24 +00:00
double sl_radius, lat_geoc;
2000-09-27 20:16:22 +00:00
sgGeodToGeoc( cur_fdm_state->get_Latitude(),
1999-11-19 02:10:24 +00:00
cur_fdm_state->get_Altitude(),
&sl_radius, &lat_geoc );
cur_fdm_state->set_Geocentric_Position( lat_geoc,
cur_fdm_state->get_Longitude(),
sl_radius + cur_fdm_state->get_Altitude() );
I tested: LaRCsim c172 on-ground and in-air starts, reset: all work UIUC Cessna172 on-ground and in-air starts work as expected, reset results in an aircraft that is upside down but does not crash FG. I don't know what it was like before, so it may well be no change. JSBSim c172 and X15 in-air starts work fine, resets now work (and are trimmed), on-ground starts do not -- the c172 ends up on its back. I suspect this is no worse than before. I did not test: Balloon (the weather code returns nan's for the atmosphere data --this is in the weather module and apparently is a linux only bug) ADA (don't know how) MagicCarpet (needs work yet) External (don't know how) known to be broken: LaRCsim c172 on-ground starts with a negative terrain altitude (this happens at KPAO when the scenery is not present). The FDM inits to about 50 feet AGL and the model falls to the ground. It does stay upright, however, and seems to be fine once it settles out, FWIW. To do: --implement set_Model on the bus --bring Christian's weather data into JSBSim -- add default method to bus for updating things like the sin and cos of latitude (for Balloon, MagicCarpet) -- lots of cleanup The files: src/FDM/flight.cxx src/FDM/flight.hxx -- all data members now declared protected instead of private. -- eliminated all but a small set of 'setters', no change to getters. -- that small set is declared virtual, the default implementation provided preserves the old behavior -- all of the vector data members are now initialized. -- added busdump() method -- FG_LOG's all the bus data when called, useful for diagnostics. src/FDM/ADA.cxx -- bus data members now directly assigned to src/FDM/Balloon.cxx -- bus data members now directly assigned to -- changed V_equiv_kts to V_calibrated_kts src/FDM/JSBSim.cxx src/FDM/JSBSim.hxx -- bus data members now directly assigned to -- implemented the FGInterface virtual setters with JSBSim specific logic -- changed the static FDMExec to a dynamic fdmex (needed so that the JSBSim object can be deleted when a model change is called for) -- implemented constructor and destructor, moved some of the logic formerly in init() to constructor -- added logic to bring up FGEngInterface objects and set the RPM and throttle values. src/FDM/LaRCsim.cxx src/FDM/LaRCsim.hxx -- bus data members now directly assigned to -- implemented the FGInterface virtual setters with LaRCsim specific logic, uses LaRCsimIC -- implemented constructor and destructor, moved some of the logic formerly in init() to constructor -- moved default inertias to here from fg_init.cxx -- eliminated the climb rate calculation. The equivalent, climb_rate = -1*vdown, is now in copy_from_LaRCsim(). src/FDM/LaRCsimIC.cxx src/FDM/LaRCsimIC.hxx -- similar to FGInitialCondition, this class has all the logic needed to turn data like Vc and Mach into the more fundamental quantities LaRCsim needs to initialize. -- put it in src/FDM since it is a class src/FDM/MagicCarpet.cxx -- bus data members now directly assigned to src/FDM/Makefile.am -- adds LaRCsimIC.hxx and cxx src/FDM/JSBSim/FGAtmosphere.h src/FDM/JSBSim/FGDefs.h src/FDM/JSBSim/FGInitialCondition.cpp src/FDM/JSBSim/FGInitialCondition.h src/FDM/JSBSim/JSBSim.cpp -- changes to accomodate the new bus src/FDM/LaRCsim/atmos_62.h src/FDM/LaRCsim/ls_geodesy.h -- surrounded prototypes with #ifdef __cplusplus ... #endif , functions here are needed in LaRCsimIC src/FDM/LaRCsim/c172_main.c src/FDM/LaRCsim/cherokee_aero.c src/FDM/LaRCsim/ls_aux.c src/FDM/LaRCsim/ls_constants.h src/FDM/LaRCsim/ls_geodesy.c src/FDM/LaRCsim/ls_geodesy.h src/FDM/LaRCsim/ls_step.c src/FDM/UIUCModel/uiuc_betaprobe.cpp -- changed PI to LS_PI, eliminates preprocessor naming conflict with weather module src/FDM/LaRCsim/ls_interface.c src/FDM/LaRCsim/ls_interface.h -- added function ls_set_model_dt() src/Main/bfi.cxx -- eliminated calls that set the NED speeds to body components. They are no longer needed and confuse the new bus. src/Main/fg_init.cxx -- eliminated calls that just brought the bus data up-to-date (e.g. set_sin_cos_latitude). or set default values. The bus now handles the defaults and updates itself when the setters are called (for LaRCsim and JSBSim). A default method for doing this needs to be added to the bus. -- added fgVelocityInit() to set the speed the user asked for. Both JSBSim and LaRCsim can now be initialized using any of: vc,mach, NED components, UVW components. src/Main/main.cxx --eliminated call to fgFDMSetGroundElevation, this data is now 'pulled' onto the bus every update() src/Main/options.cxx src/Main/options.hxx -- added enum to keep track of the speed requested by the user -- eliminated calls to set NED velocity properties to body speeds, they are no longer needed. -- added options for the NED components. src/Network/garmin.cxx src/Network/nmea.cxx --eliminated calls that just brought the bus data up-to-date (e.g. set_sin_cos_latitude). The bus now updates itself when the setters are called (for LaRCsim and JSBSim). A default method for doing this needs to be added to the bus. -- changed set_V_equiv_kts to set_V_calibrated_kts. set_V_equiv_kts no longer exists ( get_V_equiv_kts still does, though) src/WeatherCM/FGLocalWeatherDatabase.cpp -- commented out the code to put the weather data on the bus, a different scheme for this is needed.
2000-10-24 00:34:50 +00:00
#endif
1999-11-19 02:10:24 +00:00
// speed
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string speed_str = msg.substr(begin, end - begin);
begin = end + 1;
speed = atof( speed_str.c_str() );
I tested: LaRCsim c172 on-ground and in-air starts, reset: all work UIUC Cessna172 on-ground and in-air starts work as expected, reset results in an aircraft that is upside down but does not crash FG. I don't know what it was like before, so it may well be no change. JSBSim c172 and X15 in-air starts work fine, resets now work (and are trimmed), on-ground starts do not -- the c172 ends up on its back. I suspect this is no worse than before. I did not test: Balloon (the weather code returns nan's for the atmosphere data --this is in the weather module and apparently is a linux only bug) ADA (don't know how) MagicCarpet (needs work yet) External (don't know how) known to be broken: LaRCsim c172 on-ground starts with a negative terrain altitude (this happens at KPAO when the scenery is not present). The FDM inits to about 50 feet AGL and the model falls to the ground. It does stay upright, however, and seems to be fine once it settles out, FWIW. To do: --implement set_Model on the bus --bring Christian's weather data into JSBSim -- add default method to bus for updating things like the sin and cos of latitude (for Balloon, MagicCarpet) -- lots of cleanup The files: src/FDM/flight.cxx src/FDM/flight.hxx -- all data members now declared protected instead of private. -- eliminated all but a small set of 'setters', no change to getters. -- that small set is declared virtual, the default implementation provided preserves the old behavior -- all of the vector data members are now initialized. -- added busdump() method -- FG_LOG's all the bus data when called, useful for diagnostics. src/FDM/ADA.cxx -- bus data members now directly assigned to src/FDM/Balloon.cxx -- bus data members now directly assigned to -- changed V_equiv_kts to V_calibrated_kts src/FDM/JSBSim.cxx src/FDM/JSBSim.hxx -- bus data members now directly assigned to -- implemented the FGInterface virtual setters with JSBSim specific logic -- changed the static FDMExec to a dynamic fdmex (needed so that the JSBSim object can be deleted when a model change is called for) -- implemented constructor and destructor, moved some of the logic formerly in init() to constructor -- added logic to bring up FGEngInterface objects and set the RPM and throttle values. src/FDM/LaRCsim.cxx src/FDM/LaRCsim.hxx -- bus data members now directly assigned to -- implemented the FGInterface virtual setters with LaRCsim specific logic, uses LaRCsimIC -- implemented constructor and destructor, moved some of the logic formerly in init() to constructor -- moved default inertias to here from fg_init.cxx -- eliminated the climb rate calculation. The equivalent, climb_rate = -1*vdown, is now in copy_from_LaRCsim(). src/FDM/LaRCsimIC.cxx src/FDM/LaRCsimIC.hxx -- similar to FGInitialCondition, this class has all the logic needed to turn data like Vc and Mach into the more fundamental quantities LaRCsim needs to initialize. -- put it in src/FDM since it is a class src/FDM/MagicCarpet.cxx -- bus data members now directly assigned to src/FDM/Makefile.am -- adds LaRCsimIC.hxx and cxx src/FDM/JSBSim/FGAtmosphere.h src/FDM/JSBSim/FGDefs.h src/FDM/JSBSim/FGInitialCondition.cpp src/FDM/JSBSim/FGInitialCondition.h src/FDM/JSBSim/JSBSim.cpp -- changes to accomodate the new bus src/FDM/LaRCsim/atmos_62.h src/FDM/LaRCsim/ls_geodesy.h -- surrounded prototypes with #ifdef __cplusplus ... #endif , functions here are needed in LaRCsimIC src/FDM/LaRCsim/c172_main.c src/FDM/LaRCsim/cherokee_aero.c src/FDM/LaRCsim/ls_aux.c src/FDM/LaRCsim/ls_constants.h src/FDM/LaRCsim/ls_geodesy.c src/FDM/LaRCsim/ls_geodesy.h src/FDM/LaRCsim/ls_step.c src/FDM/UIUCModel/uiuc_betaprobe.cpp -- changed PI to LS_PI, eliminates preprocessor naming conflict with weather module src/FDM/LaRCsim/ls_interface.c src/FDM/LaRCsim/ls_interface.h -- added function ls_set_model_dt() src/Main/bfi.cxx -- eliminated calls that set the NED speeds to body components. They are no longer needed and confuse the new bus. src/Main/fg_init.cxx -- eliminated calls that just brought the bus data up-to-date (e.g. set_sin_cos_latitude). or set default values. The bus now handles the defaults and updates itself when the setters are called (for LaRCsim and JSBSim). A default method for doing this needs to be added to the bus. -- added fgVelocityInit() to set the speed the user asked for. Both JSBSim and LaRCsim can now be initialized using any of: vc,mach, NED components, UVW components. src/Main/main.cxx --eliminated call to fgFDMSetGroundElevation, this data is now 'pulled' onto the bus every update() src/Main/options.cxx src/Main/options.hxx -- added enum to keep track of the speed requested by the user -- eliminated calls to set NED velocity properties to body speeds, they are no longer needed. -- added options for the NED components. src/Network/garmin.cxx src/Network/nmea.cxx --eliminated calls that just brought the bus data up-to-date (e.g. set_sin_cos_latitude). The bus now updates itself when the setters are called (for LaRCsim and JSBSim). A default method for doing this needs to be added to the bus. -- changed set_V_equiv_kts to set_V_calibrated_kts. set_V_equiv_kts no longer exists ( get_V_equiv_kts still does, though) src/WeatherCM/FGLocalWeatherDatabase.cpp -- commented out the code to put the weather data on the bus, a different scheme for this is needed.
2000-10-24 00:34:50 +00:00
cur_fdm_state->set_V_calibrated_kts( speed );
// cur_fdm_state->set_V_ground_speed( speed );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
1999-11-19 02:10:24 +00:00
// heading
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string hdg_str = msg.substr(begin, end - begin);
begin = end + 1;
heading = atof( hdg_str.c_str() );
cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
2001-03-24 04:48:44 +00:00
heading * SGD_DEGREES_TO_RADIANS );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
1999-11-19 02:10:24 +00:00
} else if ( sentence == "PGRMZ" ) {
// altitude
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string alt_str = msg.substr(begin, end - begin);
altitude = atof( alt_str.c_str() );
begin = end + 1;
// altitude units
end = msg.find(",", begin);
if ( end == string::npos ) {
return false;
}
string alt_units = msg.substr(begin, end - begin);
begin = end + 1;
2001-03-26 18:22:31 +00:00
if ( alt_units != (string)"F" && alt_units != (string)"f" ) {
2001-03-24 04:56:46 +00:00
altitude *= SG_METER_TO_FEET;
1999-11-19 02:10:24 +00:00
}
cur_fdm_state->set_Altitude( altitude );
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
1999-11-19 02:10:24 +00:00
}
// printf("%.8f %.8f\n", lon, lat);
begin = begin_line;
end_line = msg.find("\n", begin_line);
}
return true;
}
// open hailing frequencies
bool FGGarmin::open() {
if ( is_enabled() ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
1999-11-19 02:10:24 +00:00
<< "is already in use, ignoring" );
return false;
}
SGIOChannel *io = get_io_channel();
1999-11-19 02:10:24 +00:00
if ( ! io->open( get_direction() ) ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
1999-11-19 02:10:24 +00:00
return false;
}
set_enabled( true );
return true;
}
// process work for this port
bool FGGarmin::process() {
SGIOChannel *io = get_io_channel();
1999-11-19 02:10:24 +00:00
if ( get_direction() == SG_IO_OUT ) {
1999-11-19 02:10:24 +00:00
gen_message();
if ( ! io->write( buf, length ) ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
1999-11-19 02:10:24 +00:00
return false;
}
} else if ( get_direction() == SG_IO_IN ) {
1999-11-22 18:08:14 +00:00
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Success reading data." );
if ( parse_message() ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Success parsing data." );
} else {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Error parsing data." );
}
1999-11-19 02:10:24 +00:00
} else {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
1999-11-19 02:10:24 +00:00
return false;
}
1999-11-22 18:08:14 +00:00
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Success reading data." );
if ( parse_message() ) {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Success parsing data." );
} else {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Error parsing data." );
}
1999-11-19 02:10:24 +00:00
} else {
2001-03-24 06:03:11 +00:00
SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
1999-11-19 02:10:24 +00:00
return false;
}
}
return true;
}
// close the channel
bool FGGarmin::close() {
SGIOChannel *io = get_io_channel();
1999-11-19 02:10:24 +00:00
set_enabled( false );
if ( ! io->close() ) {
return false;
}
return true;
}