67 char rmc[256], gga[256], patla[256];
68 char rmc_sum[10], gga_sum[10], patla_sum[10];
73 SGTime *t =
globals->get_time_params();
76 snprintf( utc,
sizeof(utc),
"%02d%02d%02d",
77 t->getGmt()->tm_hour, t->getGmt()->tm_min, t->getGmt()->tm_sec );
80 double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
88 min = (latd - (double)deg) * 60.0;
89 snprintf( lat,
sizeof(lat),
"%02d%06.3f,%c", abs(deg),
min, dir);
92 double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
100 min = (lond - (double)deg) * 60.0;
101 snprintf( lon,
sizeof(lon),
"%03d%06.3f,%c", abs(deg),
min, dir);
104 snprintf( speed,
sizeof(speed),
"%05.1f", fdm->get_V_equiv_kts() );
107 snprintf( heading,
sizeof(heading),
"%05.1f", fdm->get_Psi() * SGD_RADIANS_TO_DEGREES );
110 snprintf( altitude_m,
sizeof(altitude_m),
"%02d",
111 (
int)(fdm->get_Altitude() * SG_FEET_TO_METER) );
113 char altitude_ft[10];
114 snprintf( altitude_ft,
sizeof(altitude_ft),
"%02d", (
int)fdm->get_Altitude() );
117 unsigned short tm_mday = t->getGmt()->tm_mday;
118 unsigned short tm_mon = t->getGmt()->tm_mon + 1;
119 unsigned short tm_year = t->getGmt()->tm_year;
120 snprintf( date,
sizeof(date),
"%02u%02u%02u", tm_mday, tm_mon, tm_year);
123 snprintf( rmc,
sizeof(rmc),
"GPRMC,%s,A,%s,%s,%s,%s,%s,0.000,E",
124 utc, lat, lon, speed, heading, date );
127 snprintf( gga,
sizeof(gga),
"GPGGA,%s,%s,%s,1,,,%s,F,,,,",
128 utc, lat, lon, altitude_ft );
131 snprintf( patla,
sizeof(patla),
"PATLA,%.2f,%.1f,%.2f,%.1f,%.0f",
132 _nav1_freq->getDoubleValue(),
133 _nav1_sel_radial->getDoubleValue(),
134 _nav2_freq->getDoubleValue(),
135 _nav2_sel_radial->getDoubleValue(),
136 _adf_freq->getDoubleValue() );
139 SG_LOG( SG_IO, SG_DEBUG, rmc );
140 SG_LOG( SG_IO, SG_DEBUG, gga );
141 SG_LOG( SG_IO, SG_DEBUG, patla );
143 std::string atlas_sentence;
146 atlas_sentence =
"$";
147 atlas_sentence += rmc;
148 atlas_sentence +=
"*";
149 atlas_sentence += rmc_sum;
150 atlas_sentence +=
"\n";
153 atlas_sentence +=
"$";
154 atlas_sentence += gga;
155 atlas_sentence +=
"*";
156 atlas_sentence += gga_sum;
157 atlas_sentence +=
"\n";
160 atlas_sentence +=
"$";
161 atlas_sentence += patla;
162 atlas_sentence +=
"*";
163 atlas_sentence += patla_sum;
164 atlas_sentence +=
"\n";
168 length = atlas_sentence.length();
169 strncpy( buf, atlas_sentence.c_str(), length );
182 SG_LOG( SG_IO, SG_INFO,
"parse atlas message" );
184 std::string msg = buf;
185 msg = msg.substr( 0, length );
186 SG_LOG( SG_IO, SG_INFO,
"entire message = " << msg );
188 std::string::size_type begin_line, end_line, begin, end;
189 begin_line = begin = 0;
192 end_line = msg.find(
"\n", begin_line);
193 while ( end_line != std::string::npos ) {
194 std::string line = msg.substr(begin_line, end_line - begin_line);
195 begin_line = end_line + 1;
196 SG_LOG( SG_IO, SG_INFO,
" input line = " << line );
199 std::string start = msg.substr(begin, 1);
201 SG_LOG( SG_IO, SG_INFO,
" start = " << start );
204 end = msg.find(
",", begin);
205 if ( end == std::string::npos ) {
209 std::string sentence = msg.substr(begin, end - begin);
211 SG_LOG( SG_IO, SG_INFO,
" sentence = " << sentence );
213 double lon_deg, lon_min, lat_deg, lat_min;
214 double lon, lat, speed, heading,
altitude;
216 if ( sentence ==
"GPRMC" ) {
218 end = msg.find(
",", begin);
219 if ( end == std::string::npos ) {
223 std::string utc = msg.substr(begin, end - begin);
225 SG_LOG( SG_IO, SG_INFO,
" utc = " << utc );
228 end = msg.find(
",", begin);
229 if ( end == std::string::npos ) {
233 std::string junk = msg.substr(begin, end - begin);
235 SG_LOG( SG_IO, SG_INFO,
" junk = " << junk );
238 end = msg.find(
",", begin);
239 if ( end == std::string::npos ) {
243 std::string lat_str = msg.substr(begin, end - begin);
246 lat_deg =
atof( lat_str.substr(0, 2).c_str() );
247 lat_min =
atof( lat_str.substr(2).c_str() );
250 end = msg.find(
",", begin);
251 if ( end == std::string::npos ) {
255 std::string lat_dir = msg.substr(begin, end - begin);
258 lat = lat_deg + ( lat_min / 60.0 );
259 if ( lat_dir ==
"S" ) {
263 fdm->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
264 SG_LOG( SG_IO, SG_INFO,
" lat = " << lat );
267 end = msg.find(
",", begin);
268 if ( end == std::string::npos ) {
272 std::string lon_str = msg.substr(begin, end - begin);
275 lon_deg =
atof( lon_str.substr(0, 3).c_str() );
276 lon_min =
atof( lon_str.substr(3).c_str() );
279 end = msg.find(
",", begin);
280 if ( end == std::string::npos ) {
284 std::string lon_dir = msg.substr(begin, end - begin);
287 lon = lon_deg + ( lon_min / 60.0 );
288 if ( lon_dir ==
"W" ) {
292 fdm->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
293 SG_LOG( SG_IO, SG_INFO,
" lon = " << lon );
297 sgGeodToGeoc( fdm->get_Latitude(),
300 fdm->set_Geocentric_Position(
lat_geoc,
301 fdm->get_Longitude(),
302 sl_radius + fdm->get_Altitude() );
306 end = msg.find(
",", begin);
307 if ( end == std::string::npos ) {
311 std::string speed_str = msg.substr(begin, end - begin);
313 speed =
atof( speed_str.c_str() );
314 fdm->set_V_calibrated_kts( speed );
316 SG_LOG( SG_IO, SG_INFO,
" speed = " << speed );
319 end = msg.find(
",", begin);
320 if ( end == std::string::npos ) {
324 std::string hdg_str = msg.substr(begin, end - begin);
326 heading =
atof( hdg_str.c_str() );
327 fdm->set_Euler_Angles( fdm->get_Phi(),
329 heading * SGD_DEGREES_TO_RADIANS );
330 SG_LOG( SG_IO, SG_INFO,
" heading = " << heading );
331 }
else if ( sentence ==
"GPGGA" ) {
333 end = msg.find(
",", begin);
334 if ( end == std::string::npos ) {
338 std::string utc = msg.substr(begin, end - begin);
340 SG_LOG( SG_IO, SG_INFO,
" utc = " << utc );
343 end = msg.find(
",", begin);
344 if ( end == std::string::npos ) {
348 std::string lat_str = msg.substr(begin, end - begin);
351 lat_deg =
atof( lat_str.substr(0, 2).c_str() );
352 lat_min =
atof( lat_str.substr(2).c_str() );
355 end = msg.find(
",", begin);
356 if ( end == std::string::npos ) {
360 std::string lat_dir = msg.substr(begin, end - begin);
363 lat = lat_deg + ( lat_min / 60.0 );
364 if ( lat_dir ==
"S" ) {
369 SG_LOG( SG_IO, SG_INFO,
" lat = " << lat );
372 end = msg.find(
",", begin);
373 if ( end == std::string::npos ) {
377 std::string lon_str = msg.substr(begin, end - begin);
380 lon_deg =
atof( lon_str.substr(0, 3).c_str() );
381 lon_min =
atof( lon_str.substr(3).c_str() );
384 end = msg.find(
",", begin);
385 if ( end == std::string::npos ) {
389 std::string lon_dir = msg.substr(begin, end - begin);
392 lon = lon_deg + ( lon_min / 60.0 );
393 if ( lon_dir ==
"W" ) {
398 SG_LOG( SG_IO, SG_INFO,
" lon = " << lon );
401 end = msg.find(
",", begin);
402 if ( end == std::string::npos ) {
406 std::string junk = msg.substr(begin, end - begin);
408 SG_LOG( SG_IO, SG_INFO,
" junk = " << junk );
411 end = msg.find(
",", begin);
412 if ( end == std::string::npos ) {
416 junk = msg.substr(begin, end - begin);
418 SG_LOG( SG_IO, SG_INFO,
" junk = " << junk );
421 end = msg.find(
",", begin);
422 if ( end == std::string::npos ) {
426 junk = msg.substr(begin, end - begin);
428 SG_LOG( SG_IO, SG_INFO,
" junk = " << junk );
431 end = msg.find(
",", begin);
432 if ( end == std::string::npos ) {
436 std::string alt_str = msg.substr(begin, end - begin);
441 end = msg.find(
",", begin);
442 if ( end == std::string::npos ) {
446 std::string alt_units = msg.substr(begin, end - begin);
449 if ( alt_units !=
"F" ) {
455 SG_LOG( SG_IO, SG_INFO,
" altitude = " <<
altitude );
457 }
else if ( sentence ==
"PATLA" ) {
459 end = msg.find(
",", begin);
460 if ( end == std::string::npos ) {
464 std::string nav1_freq = msg.substr(begin, end - begin);
466 SG_LOG( SG_IO, SG_INFO,
" nav1_freq = " << nav1_freq );
469 end = msg.find(
",", begin);
470 if ( end == std::string::npos ) {
474 std::string nav1_rad = msg.substr(begin, end - begin);
476 SG_LOG( SG_IO, SG_INFO,
" nav1_rad = " << nav1_rad );
479 end = msg.find(
",", begin);
480 if ( end == std::string::npos ) {
484 std::string nav2_freq = msg.substr(begin, end - begin);
486 SG_LOG( SG_IO, SG_INFO,
" nav2_freq = " << nav2_freq );
489 end = msg.find(
",", begin);
490 if ( end == std::string::npos ) {
494 std::string nav2_rad = msg.substr(begin, end - begin);
496 SG_LOG( SG_IO, SG_INFO,
" nav2_rad = " << nav2_rad );
499 end = msg.find(
"*", begin);
500 if ( end == std::string::npos ) {
504 std::string adf_freq = msg.substr(begin, end - begin);
506 SG_LOG( SG_IO, SG_INFO,
" adf_freq = " << adf_freq );
512 end_line = msg.find(
"\n", begin_line);