2023-05-20 22:32:09 +00:00
|
|
|
/*
|
|
|
|
* SPDX-FileName: atlas.cxx
|
|
|
|
* SPDX-FileComment: Atlas protocol class
|
|
|
|
* SPDX-FileCopyrightText: Copyright (C) 1999 Curtis L. Olson - http://www.flightgear.org/~curt
|
|
|
|
* SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
*/
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2006-02-18 13:58:09 +00:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
# include "config.h"
|
|
|
|
#endif
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2013-02-07 18:00:54 +00:00
|
|
|
#include <cstdio>
|
2012-05-04 23:08:20 +00:00
|
|
|
#include <cstdlib>
|
2010-07-27 07:31:10 +00:00
|
|
|
#include <cstring>
|
|
|
|
|
2001-01-31 21:57:55 +00:00
|
|
|
#include <simgear/debug/logstream.hxx>
|
|
|
|
#include <simgear/math/sg_geodesy.hxx>
|
|
|
|
#include <simgear/io/iochannel.hxx>
|
2010-07-01 21:43:28 +00:00
|
|
|
#include <simgear/timing/sg_time.hxx>
|
2009-01-31 08:36:11 +00:00
|
|
|
|
2010-06-16 07:31:59 +00:00
|
|
|
#include <FDM/flightProperties.hxx>
|
2001-01-31 21:57:55 +00:00
|
|
|
#include <Main/globals.hxx>
|
2004-12-03 21:21:16 +00:00
|
|
|
#include <Main/fg_props.hxx>
|
|
|
|
#include <Main/fg_init.hxx>
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
#include "atlas.hxx"
|
|
|
|
|
|
|
|
|
2012-11-18 15:35:54 +00:00
|
|
|
FGAtlas::FGAtlas() :
|
|
|
|
length(0),
|
|
|
|
fdm(new FlightProperties)
|
|
|
|
{
|
|
|
|
_adf_freq = fgGetNode("/instrumentation/adf/frequencies/selected-khz", true);
|
|
|
|
_nav1_freq = fgGetNode("/instrumentation/nav/frequencies/selected-mhz", true);
|
|
|
|
_nav1_sel_radial = fgGetNode("/instrumentation/nav/radials/selected-deg", true);
|
|
|
|
_nav2_freq = fgGetNode("/instrumentation/nav[1]/frequencies/selected-mhz", true);
|
|
|
|
_nav2_sel_radial = fgGetNode("/instrumentation/nav[1]/radials/selected-deg", true);
|
2001-01-31 21:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
FGAtlas::~FGAtlas() {
|
2010-06-16 07:31:59 +00:00
|
|
|
delete fdm;
|
2001-01-31 21:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// calculate the atlas check sum
|
|
|
|
static char calc_atlas_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 Atlas message
|
|
|
|
bool FGAtlas::gen_message() {
|
|
|
|
// cout << "generating atlas message" << endl;
|
|
|
|
char rmc[256], gga[256], patla[256];
|
|
|
|
char rmc_sum[10], gga_sum[10], patla_sum[10];
|
|
|
|
char dir;
|
|
|
|
int deg;
|
|
|
|
double min;
|
|
|
|
|
|
|
|
SGTime *t = globals->get_time_params();
|
|
|
|
|
|
|
|
char utc[10];
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( utc, sizeof(utc), "%02d%02d%02d",
|
2001-01-31 21:57:55 +00:00
|
|
|
t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
|
|
|
|
|
|
|
|
char lat[20];
|
2010-06-16 07:31:59 +00:00
|
|
|
double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
|
2001-01-31 21:57:55 +00:00
|
|
|
if ( latd < 0.0 ) {
|
|
|
|
latd *= -1.0;
|
|
|
|
dir = 'S';
|
|
|
|
} else {
|
|
|
|
dir = 'N';
|
|
|
|
}
|
|
|
|
deg = (int)(latd);
|
|
|
|
min = (latd - (double)deg) * 60.0;
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( lat, sizeof(lat), "%02d%06.3f,%c", abs(deg), min, dir);
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
char lon[20];
|
2010-06-16 07:31:59 +00:00
|
|
|
double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
|
2001-01-31 21:57:55 +00:00
|
|
|
if ( lond < 0.0 ) {
|
|
|
|
lond *= -1.0;
|
|
|
|
dir = 'W';
|
|
|
|
} else {
|
|
|
|
dir = 'E';
|
|
|
|
}
|
|
|
|
deg = (int)(lond);
|
|
|
|
min = (lond - (double)deg) * 60.0;
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( lon, sizeof(lon), "%03d%06.3f,%c", abs(deg), min, dir);
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
char speed[10];
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( speed, sizeof(speed), "%05.1f", fdm->get_V_equiv_kts() );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
char heading[10];
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( heading, sizeof(heading), "%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
char altitude_m[10];
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( altitude_m, sizeof(altitude_m), "%02d",
|
2010-06-16 07:31:59 +00:00
|
|
|
(int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
char altitude_ft[10];
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( altitude_ft, sizeof(altitude_ft), "%02d", (int)fdm->get_Altitude() );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2021-02-21 21:51:08 +00:00
|
|
|
char date[16];
|
|
|
|
unsigned short tm_mday = t->getGmt()->tm_mday;
|
|
|
|
unsigned short tm_mon = t->getGmt()->tm_mon + 1;
|
|
|
|
unsigned short tm_year = t->getGmt()->tm_year;
|
|
|
|
snprintf( date, sizeof(date), "%02u%02u%02u", tm_mday, tm_mon, tm_year);
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// $GPRMC,HHMMSS,A,DDMM.MMM,N,DDDMM.MMM,W,XXX.X,XXX.X,DDMMYY,XXX.X,E*XX
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( rmc, sizeof(rmc), "GPRMC,%s,A,%s,%s,%s,%s,%s,0.000,E",
|
2001-01-31 21:57:55 +00:00
|
|
|
utc, lat, lon, speed, heading, date );
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( rmc_sum, sizeof(rmc_sum), "%02X", calc_atlas_cksum(rmc) );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( gga, sizeof(gga), "GPGGA,%s,%s,%s,1,,,%s,F,,,,",
|
2001-01-31 21:57:55 +00:00
|
|
|
utc, lat, lon, altitude_ft );
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( gga_sum, sizeof(gga_sum), "%02X", calc_atlas_cksum(gga) );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( patla, sizeof(patla), "PATLA,%.2f,%.1f,%.2f,%.1f,%.0f",
|
2012-11-18 15:35:54 +00:00
|
|
|
_nav1_freq->getDoubleValue(),
|
|
|
|
_nav1_sel_radial->getDoubleValue(),
|
|
|
|
_nav2_freq->getDoubleValue(),
|
|
|
|
_nav2_sel_radial->getDoubleValue(),
|
|
|
|
_adf_freq->getDoubleValue() );
|
2020-06-14 17:21:06 +00:00
|
|
|
snprintf( patla_sum, sizeof(patla_sum), "%02X", calc_atlas_cksum(patla) );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_DEBUG, rmc );
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, gga );
|
|
|
|
SG_LOG( SG_IO, SG_DEBUG, patla );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string atlas_sentence;
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// RMC sentence
|
|
|
|
atlas_sentence = "$";
|
|
|
|
atlas_sentence += rmc;
|
|
|
|
atlas_sentence += "*";
|
|
|
|
atlas_sentence += rmc_sum;
|
|
|
|
atlas_sentence += "\n";
|
|
|
|
|
|
|
|
// GGA sentence
|
|
|
|
atlas_sentence += "$";
|
|
|
|
atlas_sentence += gga;
|
|
|
|
atlas_sentence += "*";
|
|
|
|
atlas_sentence += gga_sum;
|
|
|
|
atlas_sentence += "\n";
|
|
|
|
|
|
|
|
// PATLA sentence
|
|
|
|
atlas_sentence += "$";
|
|
|
|
atlas_sentence += patla;
|
|
|
|
atlas_sentence += "*";
|
|
|
|
atlas_sentence += patla_sum;
|
|
|
|
atlas_sentence += "\n";
|
|
|
|
|
2004-02-07 21:37:35 +00:00
|
|
|
// cout << atlas_sentence;
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
length = atlas_sentence.length();
|
|
|
|
strncpy( buf, atlas_sentence.c_str(), length );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// parse Atlas message. messages will look something like the
|
|
|
|
// following:
|
|
|
|
//
|
|
|
|
// $GPRMC,163227,A,3321.173,N,11039.855,W,000.1,270.0,171199,0.000,E*61
|
|
|
|
// $GPGGA,163227,3321.173,N,11039.855,W,1,,,3333,F,,,,*0F
|
|
|
|
|
|
|
|
bool FGAtlas::parse_message() {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, "parse atlas message" );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string msg = buf;
|
2001-01-31 21:57:55 +00:00
|
|
|
msg = msg.substr( 0, length );
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, "entire message = " << msg );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string::size_type begin_line, end_line, begin, end;
|
2001-01-31 21:57:55 +00:00
|
|
|
begin_line = begin = 0;
|
|
|
|
|
|
|
|
// extract out each line
|
|
|
|
end_line = msg.find("\n", begin_line);
|
2023-05-20 22:32:09 +00:00
|
|
|
while ( end_line != std::string::npos ) {
|
|
|
|
std::string line = msg.substr(begin_line, end_line - begin_line);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin_line = end_line + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " input line = " << line );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// leading character
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string start = msg.substr(begin, 1);
|
2001-01-31 21:57:55 +00:00
|
|
|
++begin;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " start = " << start );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// sentence
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string sentence = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " sentence = " << sentence );
|
2001-01-31 21:57:55 +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);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string utc = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " utc = " << utc );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// junk
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string junk = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// lat val
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lat_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
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);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lat_dir = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
|
|
|
|
lat = lat_deg + ( lat_min / 60.0 );
|
|
|
|
if ( lat_dir == "S" ) {
|
|
|
|
lat *= -1;
|
|
|
|
}
|
|
|
|
|
2010-06-16 07:31:59 +00:00
|
|
|
fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// lon val
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lon_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
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);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lon_dir = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
|
|
|
|
lon = lon_deg + ( lon_min / 60.0 );
|
|
|
|
if ( lon_dir == "W" ) {
|
|
|
|
lon *= -1;
|
|
|
|
}
|
|
|
|
|
2010-06-16 07:31:59 +00:00
|
|
|
fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
#if 0
|
|
|
|
double sl_radius, lat_geoc;
|
2010-06-16 07:31:59 +00:00
|
|
|
sgGeodToGeoc( fdm->get_Latitude(),
|
|
|
|
fdm->get_Altitude(),
|
2001-01-31 21:57:55 +00:00
|
|
|
&sl_radius, &lat_geoc );
|
2010-06-16 07:31:59 +00:00
|
|
|
fdm->set_Geocentric_Position( lat_geoc,
|
|
|
|
fdm->get_Longitude(),
|
|
|
|
sl_radius + fdm->get_Altitude() );
|
2001-01-31 21:57:55 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
// speed
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string speed_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
speed = atof( speed_str.c_str() );
|
2010-06-16 07:31:59 +00:00
|
|
|
fdm->set_V_calibrated_kts( speed );
|
|
|
|
// fdm->set_V_ground_speed( speed );
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// heading
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string hdg_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
heading = atof( hdg_str.c_str() );
|
2010-06-16 07:31:59 +00:00
|
|
|
fdm->set_Euler_Angles( fdm->get_Phi(),
|
|
|
|
fdm->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 );
|
2001-01-31 21:57:55 +00:00
|
|
|
} else if ( sentence == "GPGGA" ) {
|
|
|
|
// time
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string utc = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " utc = " << utc );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// lat val
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lat_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
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);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lat_dir = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
|
|
|
|
lat = lat_deg + ( lat_min / 60.0 );
|
|
|
|
if ( lat_dir == "S" ) {
|
|
|
|
lat *= -1;
|
|
|
|
}
|
|
|
|
|
2010-06-16 07:31:59 +00:00
|
|
|
// fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// lon val
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lon_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
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);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string lon_dir = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
|
|
|
|
lon = lon_deg + ( lon_min / 60.0 );
|
|
|
|
if ( lon_dir == "W" ) {
|
|
|
|
lon *= -1;
|
|
|
|
}
|
|
|
|
|
2010-06-16 07:31:59 +00:00
|
|
|
// fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " lon = " << lon );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// junk
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string junk = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " junk = " << junk );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// junk
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// junk
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
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 );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
|
|
|
// altitude
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string alt_str = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
altitude = atof( alt_str.c_str() );
|
|
|
|
begin = end + 1;
|
|
|
|
|
|
|
|
// altitude units
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string alt_units = msg.substr(begin, end - begin);
|
2001-01-31 21:57:55 +00:00
|
|
|
begin = end + 1;
|
|
|
|
|
2003-10-16 14:14:03 +00:00
|
|
|
if ( alt_units != "F" ) {
|
2001-03-24 04:56:46 +00:00
|
|
|
altitude *= SG_METER_TO_FEET;
|
2001-01-31 21:57:55 +00:00
|
|
|
}
|
|
|
|
|
2010-06-16 07:31:59 +00:00
|
|
|
fdm->set_Altitude( altitude );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );
|
2001-01-31 21:57:55 +00:00
|
|
|
|
2001-01-31 22:21:36 +00:00
|
|
|
} else if ( sentence == "PATLA" ) {
|
|
|
|
// nav1 freq
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 22:21:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string nav1_freq = msg.substr(begin, end - begin);
|
2001-01-31 22:21:36 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " nav1_freq = " << nav1_freq );
|
2001-01-31 22:21:36 +00:00
|
|
|
|
|
|
|
// nav1 selected radial
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 22:21:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string nav1_rad = msg.substr(begin, end - begin);
|
2001-01-31 22:21:36 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " nav1_rad = " << nav1_rad );
|
2001-01-31 22:21:36 +00:00
|
|
|
|
|
|
|
// nav2 freq
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 22:21:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string nav2_freq = msg.substr(begin, end - begin);
|
2001-01-31 22:21:36 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " nav2_freq = " << nav2_freq );
|
2001-01-31 22:21:36 +00:00
|
|
|
|
|
|
|
// nav2 selected radial
|
|
|
|
end = msg.find(",", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 22:21:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string nav2_rad = msg.substr(begin, end - begin);
|
2001-01-31 22:21:36 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " nav2_rad = " << nav2_rad );
|
2001-01-31 22:21:36 +00:00
|
|
|
|
|
|
|
// adf freq
|
|
|
|
end = msg.find("*", begin);
|
2023-05-20 22:32:09 +00:00
|
|
|
if ( end == std::string::npos ) {
|
2001-01-31 22:21:36 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2023-05-20 22:32:09 +00:00
|
|
|
std::string adf_freq = msg.substr(begin, end - begin);
|
2001-01-31 22:21:36 +00:00
|
|
|
begin = end + 1;
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, " adf_freq = " << adf_freq );
|
2001-01-31 21:57:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// printf("%.8f %.8f\n", lon, lat);
|
|
|
|
|
|
|
|
begin = begin_line;
|
|
|
|
end_line = msg.find("\n", begin_line);
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// open hailing frequencies
|
|
|
|
bool FGAtlas::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 "
|
2001-01-31 21:57:55 +00:00
|
|
|
<< "is already in use, ignoring" );
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
SGIOChannel *io = get_io_channel();
|
|
|
|
|
|
|
|
if ( ! io->open( get_direction() ) ) {
|
2001-03-24 06:03:11 +00:00
|
|
|
SG_LOG( SG_IO, SG_ALERT, "Error opening channel communication layer." );
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
set_enabled( true );
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// process work for this port
|
|
|
|
bool FGAtlas::process() {
|
|
|
|
SGIOChannel *io = get_io_channel();
|
|
|
|
|
|
|
|
if ( get_direction() == SG_IO_OUT ) {
|
|
|
|
gen_message();
|
|
|
|
if ( ! io->write( buf, length ) ) {
|
2004-02-07 21:37:35 +00:00
|
|
|
SG_LOG( SG_IO, SG_WARN, "Error writing data." );
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
} else if ( get_direction() == SG_IO_IN ) {
|
|
|
|
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
|
|
|
|
parse_message();
|
|
|
|
} else {
|
2004-02-07 21:37:35 +00:00
|
|
|
SG_LOG( SG_IO, SG_WARN, "Error reading data." );
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
if ( (length = io->readline( buf, FG_MAX_MSG_SIZE )) > 0 ) {
|
|
|
|
parse_message();
|
|
|
|
} else {
|
2004-02-07 21:37:35 +00:00
|
|
|
SG_LOG( SG_IO, SG_WARN, "Error reading data." );
|
2001-01-31 21:57:55 +00:00
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// close the channel
|
|
|
|
bool FGAtlas::close() {
|
2004-04-25 02:06:55 +00:00
|
|
|
SG_LOG( SG_IO, SG_INFO, "closing FGAtlas" );
|
2001-01-31 21:57:55 +00:00
|
|
|
SGIOChannel *io = get_io_channel();
|
|
|
|
|
|
|
|
set_enabled( false );
|
|
|
|
|
|
|
|
if ( ! io->close() ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|