X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2Fgarmin.cxx;h=590a92fdaae5f736e8f1ccd46363f23a13693d4d;hb=5aee96c481e99a4b17fc9df4b7959ae2fa89ac2c;hp=ca00dd414f3d6accdac829e02cb07ec9fc76ad33;hpb=32528d0cd65eb1aec904f25b692b2f961c028bfa;p=flightgear.git diff --git a/src/Network/garmin.cxx b/src/Network/garmin.cxx index ca00dd414..590a92fda 100644 --- a/src/Network/garmin.cxx +++ b/src/Network/garmin.cxx @@ -24,12 +24,14 @@ #include #include #include +#include #include #include
#include "garmin.hxx" +SG_USING_NAMESPACE(std); FGGarmin::FGGarmin() { } @@ -74,7 +76,7 @@ bool FGGarmin::gen_message() { 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'; @@ -86,7 +88,7 @@ bool FGGarmin::gen_message() { 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'; @@ -101,11 +103,11 @@ bool FGGarmin::gen_message() { 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() ); @@ -125,8 +127,8 @@ bool FGGarmin::gen_message() { sprintf( rmz, "PGRMZ,%s,f,3", altitude_ft ); sprintf( rmz_sum, "%02X", calc_nmea_cksum(rmz) ); - FG_LOG( FG_IO, FG_DEBUG, rmc ); - FG_LOG( FG_IO, FG_DEBUG, rmz ); + SG_LOG( SG_IO, SG_DEBUG, rmc ); + SG_LOG( SG_IO, SG_DEBUG, rmz ); string garmin_sentence; @@ -155,11 +157,11 @@ bool FGGarmin::gen_message() { // parse Garmin message bool FGGarmin::parse_message() { - FG_LOG( FG_IO, FG_INFO, "parse garmin message" ); + SG_LOG( SG_IO, SG_INFO, "parse garmin 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; @@ -169,12 +171,12 @@ bool FGGarmin::parse_message() { 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); @@ -184,7 +186,7 @@ bool FGGarmin::parse_message() { 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; @@ -198,7 +200,7 @@ bool FGGarmin::parse_message() { 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); @@ -208,7 +210,7 @@ bool FGGarmin::parse_message() { 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); @@ -236,8 +238,8 @@ bool FGGarmin::parse_message() { 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); @@ -265,9 +267,10 @@ bool FGGarmin::parse_message() { 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(), @@ -275,6 +278,7 @@ bool FGGarmin::parse_message() { 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); @@ -285,9 +289,9 @@ bool FGGarmin::parse_message() { 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); @@ -300,8 +304,8 @@ bool FGGarmin::parse_message() { 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 == "PGRMZ" ) { // altitude end = msg.find(",", begin); @@ -322,13 +326,13 @@ bool FGGarmin::parse_message() { string alt_units = msg.substr(begin, end - begin); begin = end + 1; - if ( alt_units != "F" && alt_units != "f" ) { - altitude *= METER_TO_FEET; + if ( alt_units != (string)"F" && alt_units != (string)"f" ) { + 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 ); } @@ -345,7 +349,7 @@ bool FGGarmin::parse_message() { // open hailing frequencies bool FGGarmin::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; } @@ -353,7 +357,7 @@ bool FGGarmin::open() { 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; } @@ -370,30 +374,30 @@ bool FGGarmin::process() { 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 ) { - FG_LOG( FG_IO, FG_ALERT, "Success reading data." ); + SG_LOG( SG_IO, SG_ALERT, "Success reading data." ); if ( parse_message() ) { - FG_LOG( FG_IO, FG_ALERT, "Success parsing data." ); + SG_LOG( SG_IO, SG_ALERT, "Success parsing data." ); } else { - FG_LOG( FG_IO, FG_ALERT, "Error parsing data." ); + SG_LOG( SG_IO, SG_ALERT, "Error parsing data." ); } } 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 ) { - FG_LOG( FG_IO, FG_ALERT, "Success reading data." ); + SG_LOG( SG_IO, SG_ALERT, "Success reading data." ); if ( parse_message() ) { - FG_LOG( FG_IO, FG_ALERT, "Success parsing data." ); + SG_LOG( SG_IO, SG_ALERT, "Success parsing data." ); } else { - FG_LOG( FG_IO, FG_ALERT, "Error parsing data." ); + SG_LOG( SG_IO, SG_ALERT, "Error parsing data." ); } } else { - FG_LOG( FG_IO, FG_ALERT, "Error reading data." ); + SG_LOG( SG_IO, SG_ALERT, "Error reading data." ); return false; } }