- 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;
- SG_LOG( SG_IO, SG_INFO, " input line = " << line );
-
- // leading character
- string start = msg.substr(begin, 1);
- ++begin;
- SG_LOG( SG_IO, SG_INFO, " start = " << start );
-
- // sentence
- end = msg.find(",", begin);
- if ( end == string::npos ) {
- return false;
- }
-
- string sentence = msg.substr(begin, end - begin);
- begin = end + 1;
- SG_LOG( SG_IO, SG_INFO, " sentence = " << sentence );
-
- 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;
- SG_LOG( SG_IO, SG_INFO, " utc = " << utc );
-
- // junk
- end = msg.find(",", begin);
- if ( end == string::npos ) {
- return false;
- }
-
- string junk = msg.substr(begin, end - begin);
- begin = end + 1;
- SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
-
- // 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;
- }
-
- cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
- SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
-
- // 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;
- }
-
- 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(),
- &sl_radius, &lat_geoc );
- 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);
- if ( end == string::npos ) {
- return false;
- }
-
- 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 );
- SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
-
- // 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(),
- heading * SGD_DEGREES_TO_RADIANS );
- SG_LOG( SG_IO, SG_INFO, " heading = " << heading );
- } 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;
-
- if ( alt_units != "F" && alt_units != "f" ) {
- altitude *= SG_METER_TO_FEET;