#include <simgear/debug/logstream.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/io/iochannel.hxx>
+#include <simgear/timing/sg_time.hxx>
#include <FDM/flight.hxx>
#include <Main/globals.hxx>
#include "nmea.hxx"
+SG_USING_NAMESPACE(std);
+
FGNMEA::FGNMEA() {
}
t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
char lat[20];
- double latd = cur_fdm_state->get_Latitude() * RAD_TO_DEG;
+ double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd *= -1.0;
dir = 'S';
sprintf( lat, "%02d%06.3f,%c", abs(deg), min, dir);
char lon[20];
- double lond = cur_fdm_state->get_Longitude() * RAD_TO_DEG;
+ double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond *= -1.0;
dir = 'W';
sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() );
char heading[10];
- sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * RAD_TO_DEG );
+ sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * SGD_RADIANS_TO_DEGREES );
char altitude_m[10];
sprintf( altitude_m, "%02d",
- (int)(cur_fdm_state->get_Altitude() * FEET_TO_METER) );
+ (int)(cur_fdm_state->get_Altitude() * SG_FEET_TO_METER) );
char altitude_ft[10];
sprintf( altitude_ft, "%02d", (int)cur_fdm_state->get_Altitude() );
sprintf( gga_sum, "%02X", calc_nmea_cksum(gga) );
- FG_LOG( FG_IO, FG_DEBUG, rmc );
- FG_LOG( FG_IO, FG_DEBUG, gga );
+ SG_LOG( SG_IO, SG_DEBUG, rmc );
+ SG_LOG( SG_IO, SG_DEBUG, gga );
string nmea_sentence;
// $GPGGA,163227,3321.173,N,11039.855,W,1,,,3333,F,,,,*0F
bool FGNMEA::parse_message() {
- FG_LOG( FG_IO, FG_INFO, "parse nmea message" );
+ SG_LOG( SG_IO, SG_INFO, "parse nmea message" );
string msg = buf;
msg = msg.substr( 0, length );
- FG_LOG( FG_IO, FG_INFO, "entire message = " << msg );
+ SG_LOG( SG_IO, SG_INFO, "entire message = " << msg );
string::size_type begin_line, end_line, begin, end;
begin_line = begin = 0;
while ( end_line != string::npos ) {
string line = msg.substr(begin_line, end_line - begin_line);
begin_line = end_line + 1;
- FG_LOG( FG_IO, FG_INFO, " input line = " << line );
+ SG_LOG( SG_IO, SG_INFO, " input line = " << line );
// leading character
string start = msg.substr(begin, 1);
++begin;
- FG_LOG( FG_IO, FG_INFO, " start = " << start );
+ SG_LOG( SG_IO, SG_INFO, " start = " << start );
// sentence
end = msg.find(",", begin);
string sentence = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " sentence = " << sentence );
+ SG_LOG( SG_IO, SG_INFO, " sentence = " << sentence );
double lon_deg, lon_min, lat_deg, lat_min;
double lon, lat, speed, heading, altitude;
string utc = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " utc = " << utc );
+ SG_LOG( SG_IO, SG_INFO, " utc = " << utc );
// junk
end = msg.find(",", begin);
string junk = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " junk = " << junk );
+ SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
// lat val
end = msg.find(",", begin);
lat *= -1;
}
- cur_fdm_state->set_Latitude( lat * DEG_TO_RAD );
- FG_LOG( FG_IO, FG_INFO, " lat = " << lat );
+ cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+ SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
end = msg.find(",", begin);
lon *= -1;
}
- cur_fdm_state->set_Longitude( lon * DEG_TO_RAD );
- FG_LOG( FG_IO, FG_INFO, " lon = " << lon );
+ cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+ SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
+#if 0
double sl_radius, lat_geoc;
sgGeodToGeoc( cur_fdm_state->get_Latitude(),
cur_fdm_state->get_Altitude(),
cur_fdm_state->set_Geocentric_Position( lat_geoc,
cur_fdm_state->get_Longitude(),
sl_radius + cur_fdm_state->get_Altitude() );
+#endif
// speed
end = msg.find(",", begin);
string speed_str = msg.substr(begin, end - begin);
begin = end + 1;
speed = atof( speed_str.c_str() );
- cur_fdm_state->set_V_equiv_kts( speed );
- cur_fdm_state->set_V_ground_speed( speed );
- FG_LOG( FG_IO, FG_INFO, " speed = " << speed );
+ cur_fdm_state->set_V_calibrated_kts( speed );
+ // cur_fdm_state->set_V_ground_speed( speed );
+ SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
// heading
end = msg.find(",", begin);
heading = atof( hdg_str.c_str() );
cur_fdm_state->set_Euler_Angles( cur_fdm_state->get_Phi(),
cur_fdm_state->get_Theta(),
- heading * DEG_TO_RAD );
- FG_LOG( FG_IO, FG_INFO, " heading = " << heading );
+ heading * SGD_DEGREES_TO_RADIANS );
+ SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
} else if ( sentence == "GPGGA" ) {
// time
end = msg.find(",", begin);
string utc = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " utc = " << utc );
+ SG_LOG( SG_IO, SG_INFO, " utc = " << utc );
// lat val
end = msg.find(",", begin);
lat *= -1;
}
- // cur_fdm_state->set_Latitude( lat * DEG_TO_RAD );
- FG_LOG( FG_IO, FG_INFO, " lat = " << lat );
+ // cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+ SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
end = msg.find(",", begin);
lon *= -1;
}
- // cur_fdm_state->set_Longitude( lon * DEG_TO_RAD );
- FG_LOG( FG_IO, FG_INFO, " lon = " << lon );
+ // cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+ SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
// junk
end = msg.find(",", begin);
string junk = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " junk = " << junk );
+ SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
// junk
end = msg.find(",", begin);
junk = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " junk = " << junk );
+ SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
// junk
end = msg.find(",", begin);
junk = msg.substr(begin, end - begin);
begin = end + 1;
- FG_LOG( FG_IO, FG_INFO, " junk = " << junk );
+ SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
// altitude
end = msg.find(",", begin);
begin = end + 1;
if ( alt_units != "F" ) {
- altitude *= METER_TO_FEET;
+ altitude *= SG_METER_TO_FEET;
}
cur_fdm_state->set_Altitude( altitude );
- FG_LOG( FG_IO, FG_INFO, " altitude = " << altitude );
+ SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
}
// open hailing frequencies
bool FGNMEA::open() {
if ( is_enabled() ) {
- FG_LOG( FG_IO, FG_ALERT, "This shouldn't happen, but the channel "
+ SG_LOG( SG_IO, SG_ALERT, "This shouldn't happen, but the channel "
<< "is already in use, ignoring" );
return false;
}
SGIOChannel *io = get_io_channel();
if ( ! io->open( get_direction() ) ) {
- FG_LOG( FG_IO, FG_ALERT, "Error opening channel communication layer." );
+ SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
return false;
}
if ( get_direction() == SG_IO_OUT ) {
gen_message();
if ( ! io->write( buf, length ) ) {
- FG_LOG( FG_IO, FG_ALERT, "Error writing data." );
+ SG_LOG( SG_IO, SG_ALERT, "Error writing data." );
return false;
}
} else if ( get_direction() == SG_IO_IN ) {
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
parse_message();
} else {
- FG_LOG( FG_IO, FG_ALERT, "Error reading data." );
+ SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
return false;
}
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
parse_message();
} else {
- FG_LOG( FG_IO, FG_ALERT, "Error reading data." );
+ SG_LOG( SG_IO, SG_ALERT, "Error reading data." );
return false;
}
}