X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=src%2FNetwork%2Fatlas.cxx;h=4a2cd9d64911be983546731be43460db784e7d11;hb=4c7fb6c91bbf17119407748d4d49d627748ad037;hp=a56721d8dae98fd5af428356c914fc7b9e739c07;hpb=c7f1c662a104b7392ee577361bef9f1b1cc40df9;p=flightgear.git diff --git a/src/Network/atlas.cxx b/src/Network/atlas.cxx index a56721d8d..4a2cd9d64 100644 --- a/src/Network/atlas.cxx +++ b/src/Network/atlas.cxx @@ -2,7 +2,7 @@ // // Written by Curtis Olson, started November 1999. // -// Copyright (C) 1999 Curtis L. Olson - curt@flightgear.org +// Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt // // This program is free software; you can redistribute it and/or // modify it under the terms of the GNU General Public License as @@ -16,26 +16,35 @@ // // 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. +// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. // // $Id$ +#ifdef HAVE_CONFIG_H +# include "config.h" +#endif + +#include #include #include #include +#include -#include -#include +#include #include
+#include
+#include
#include "atlas.hxx" FGAtlas::FGAtlas() { + fdm = new FlightProperties; } FGAtlas::~FGAtlas() { + delete fdm; } @@ -58,11 +67,21 @@ static char calc_atlas_cksum(char *sentence) { return sum; } - // generate Atlas message bool FGAtlas::gen_message() { // cout << "generating atlas message" << endl; + static SGPropertyNode *adf_freq + = fgGetNode("/instrumentation/adf/frequencies/selected-khz", true); + static SGPropertyNode *nav1_freq + = fgGetNode("/instrumentation/nav/frequencies/selected-mhz", true); + static SGPropertyNode *nav1_sel_radial + = fgGetNode("/instrumentation/nav/radials/selected-deg", true); + static SGPropertyNode *nav2_freq + = fgGetNode("/instrumentation/nav[1]/frequencies/selected-mhz", true); + static SGPropertyNode *nav2_sel_radial + = fgGetNode("/instrumentation/nav[1]/radials/selected-deg", true); + char rmc[256], gga[256], patla[256]; char rmc_sum[10], gga_sum[10], patla_sum[10]; char dir; @@ -76,7 +95,7 @@ bool FGAtlas::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 = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES; if ( latd < 0.0 ) { latd *= -1.0; dir = 'S'; @@ -88,7 +107,7 @@ bool FGAtlas::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 = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES; if ( lond < 0.0 ) { lond *= -1.0; dir = 'W'; @@ -100,17 +119,17 @@ bool FGAtlas::gen_message() { sprintf( lon, "%03d%06.3f,%c", abs(deg), min, dir); char speed[10]; - sprintf( speed, "%05.1f", cur_fdm_state->get_V_equiv_kts() ); + sprintf( speed, "%05.1f", fdm->get_V_equiv_kts() ); char heading[10]; - sprintf( heading, "%05.1f", cur_fdm_state->get_Psi() * RAD_TO_DEG ); + sprintf( heading, "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES ); char altitude_m[10]; sprintf( altitude_m, "%02d", - (int)(cur_fdm_state->get_Altitude() * FEET_TO_METER) ); + (int)(fdm->get_Altitude() * SG_FEET_TO_METER) ); char altitude_ft[10]; - sprintf( altitude_ft, "%02d", (int)cur_fdm_state->get_Altitude() ); + sprintf( altitude_ft, "%02d", (int)fdm->get_Altitude() ); char date[10]; sprintf( date, "%02d%02d%02d", t->getGmt()->tm_mday, @@ -126,16 +145,16 @@ bool FGAtlas::gen_message() { sprintf( gga_sum, "%02X", calc_atlas_cksum(gga) ); sprintf( patla, "PATLA,%.2f,%.1f,%.2f,%.1f,%.0f", - current_radiostack->get_nav1_freq(), - current_radiostack->get_nav1_sel_radial(), - current_radiostack->get_nav2_freq(), - current_radiostack->get_nav2_sel_radial(), - current_radiostack->get_adf_freq() ); + nav1_freq->getDoubleValue(), + nav1_sel_radial->getDoubleValue(), + nav2_freq->getDoubleValue(), + nav2_sel_radial->getDoubleValue(), + adf_freq->getDoubleValue() ); sprintf( patla_sum, "%02X", calc_atlas_cksum(patla) ); - FG_LOG( FG_IO, FG_DEBUG, rmc ); - FG_LOG( FG_IO, FG_DEBUG, gga ); - FG_LOG( FG_IO, FG_DEBUG, patla ); + SG_LOG( SG_IO, SG_DEBUG, rmc ); + SG_LOG( SG_IO, SG_DEBUG, gga ); + SG_LOG( SG_IO, SG_DEBUG, patla ); string atlas_sentence; @@ -160,7 +179,7 @@ bool FGAtlas::gen_message() { atlas_sentence += patla_sum; atlas_sentence += "\n"; - cout << atlas_sentence; + // cout << atlas_sentence; length = atlas_sentence.length(); strncpy( buf, atlas_sentence.c_str(), length ); @@ -176,11 +195,11 @@ bool FGAtlas::gen_message() { // $GPGGA,163227,3321.173,N,11039.855,W,1,,,3333,F,,,,*0F bool FGAtlas::parse_message() { - FG_LOG( FG_IO, FG_INFO, "parse atlas message" ); + SG_LOG( SG_IO, SG_INFO, "parse atlas 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; @@ -190,12 +209,12 @@ bool FGAtlas::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); @@ -205,7 +224,7 @@ bool FGAtlas::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; @@ -219,7 +238,7 @@ bool FGAtlas::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); @@ -229,7 +248,7 @@ bool FGAtlas::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); @@ -257,8 +276,8 @@ bool FGAtlas::parse_message() { lat *= -1; } - cur_fdm_state->set_Latitude( lat * DEG_TO_RAD ); - FG_LOG( FG_IO, FG_INFO, " lat = " << lat ); + fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS ); + SG_LOG( SG_IO, SG_INFO, " lat = " << lat ); // lon val end = msg.find(",", begin); @@ -286,17 +305,17 @@ bool FGAtlas::parse_message() { lon *= -1; } - cur_fdm_state->set_Longitude( lon * DEG_TO_RAD ); - FG_LOG( FG_IO, FG_INFO, " lon = " << lon ); + fdm->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(), + sgGeodToGeoc( fdm->get_Latitude(), + fdm->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() ); + fdm->set_Geocentric_Position( lat_geoc, + fdm->get_Longitude(), + sl_radius + fdm->get_Altitude() ); #endif // speed @@ -308,9 +327,9 @@ bool FGAtlas::parse_message() { string speed_str = msg.substr(begin, end - begin); begin = end + 1; speed = atof( speed_str.c_str() ); - cur_fdm_state->set_V_calibrated_kts( speed ); - // cur_fdm_state->set_V_ground_speed( speed ); - FG_LOG( FG_IO, FG_INFO, " speed = " << speed ); + fdm->set_V_calibrated_kts( speed ); + // fdm->set_V_ground_speed( speed ); + SG_LOG( SG_IO, SG_INFO, " speed = " << speed ); // heading end = msg.find(",", begin); @@ -321,10 +340,10 @@ bool FGAtlas::parse_message() { 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(), - heading * DEG_TO_RAD ); - FG_LOG( FG_IO, FG_INFO, " heading = " << heading ); + fdm->set_Euler_Angles( fdm->get_Phi(), + fdm->get_Theta(), + heading * SGD_DEGREES_TO_RADIANS ); + SG_LOG( SG_IO, SG_INFO, " heading = " << heading ); } else if ( sentence == "GPGGA" ) { // time end = msg.find(",", begin); @@ -334,7 +353,7 @@ bool FGAtlas::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 ); // lat val end = msg.find(",", begin); @@ -362,8 +381,8 @@ bool FGAtlas::parse_message() { lat *= -1; } - // cur_fdm_state->set_Latitude( lat * DEG_TO_RAD ); - FG_LOG( FG_IO, FG_INFO, " lat = " << lat ); + // fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS ); + SG_LOG( SG_IO, SG_INFO, " lat = " << lat ); // lon val end = msg.find(",", begin); @@ -391,8 +410,8 @@ bool FGAtlas::parse_message() { lon *= -1; } - // cur_fdm_state->set_Longitude( lon * DEG_TO_RAD ); - FG_LOG( FG_IO, FG_INFO, " lon = " << lon ); + // fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS ); + SG_LOG( SG_IO, SG_INFO, " lon = " << lon ); // junk end = msg.find(",", begin); @@ -402,7 +421,7 @@ bool FGAtlas::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 ); // junk end = msg.find(",", begin); @@ -412,7 +431,7 @@ bool FGAtlas::parse_message() { 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); @@ -422,7 +441,7 @@ bool FGAtlas::parse_message() { 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); @@ -444,13 +463,63 @@ bool FGAtlas::parse_message() { begin = end + 1; if ( alt_units != "F" ) { - altitude *= METER_TO_FEET; + altitude *= SG_METER_TO_FEET; } - cur_fdm_state->set_Altitude( altitude ); + fdm->set_Altitude( altitude ); - FG_LOG( FG_IO, FG_INFO, " altitude = " << altitude ); + SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude ); + } else if ( sentence == "PATLA" ) { + // nav1 freq + end = msg.find(",", begin); + if ( end == string::npos ) { + return false; + } + + string nav1_freq = msg.substr(begin, end - begin); + begin = end + 1; + SG_LOG( SG_IO, SG_INFO, " nav1_freq = " << nav1_freq ); + + // nav1 selected radial + end = msg.find(",", begin); + if ( end == string::npos ) { + return false; + } + + string nav1_rad = msg.substr(begin, end - begin); + begin = end + 1; + SG_LOG( SG_IO, SG_INFO, " nav1_rad = " << nav1_rad ); + + // nav2 freq + end = msg.find(",", begin); + if ( end == string::npos ) { + return false; + } + + string nav2_freq = msg.substr(begin, end - begin); + begin = end + 1; + SG_LOG( SG_IO, SG_INFO, " nav2_freq = " << nav2_freq ); + + // nav2 selected radial + end = msg.find(",", begin); + if ( end == string::npos ) { + return false; + } + + string nav2_rad = msg.substr(begin, end - begin); + begin = end + 1; + SG_LOG( SG_IO, SG_INFO, " nav2_rad = " << nav2_rad ); + + // adf freq + end = msg.find("*", begin); + if ( end == string::npos ) { + return false; + } + + string adf_freq = msg.substr(begin, end - begin); + begin = end + 1; + SG_LOG( SG_IO, SG_INFO, " adf_freq = " << adf_freq ); } // printf("%.8f %.8f\n", lon, lat); @@ -466,7 +535,7 @@ bool FGAtlas::parse_message() { // open hailing frequencies bool FGAtlas::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; } @@ -474,7 +543,7 @@ bool FGAtlas::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; } @@ -491,20 +560,20 @@ bool FGAtlas::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_WARN, "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_WARN, "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_WARN, "Error reading data." ); return false; } } @@ -515,6 +584,7 @@ bool FGAtlas::process() { // close the channel bool FGAtlas::close() { + SG_LOG( SG_IO, SG_INFO, "closing FGAtlas" ); SGIOChannel *io = get_io_channel(); set_enabled( false );