# include "config.h"
#endif
+#include <cstdlib>
+#include <cstring>
+
#include <simgear/debug/logstream.hxx>
#include <simgear/math/sg_geodesy.hxx>
#include <simgear/io/iochannel.hxx>
#include <simgear/timing/sg_time.hxx>
-#include <FDM/flight.hxx>
#include <Main/fg_props.hxx>
#include <Main/globals.hxx>
#include "AV400.hxx"
-SG_USING_NAMESPACE(std);
-
FGAV400::FGAV400() {
}
}
+#if 0
// calculate the garmin check sum
static char calc_nmea_cksum(char *sentence) {
unsigned char sum = 0;
// printf("sum = %02x\n", sum);
return sum;
}
+#endif
// generate AV400 message
double min;
// create msg_z
- sprintf( msg_z, "z%05.0f\n", cur_fdm_state->get_Altitude() );
+ sprintf( msg_z, "z%05.0f\r\n", fdm.get_Altitude() );
// create msg_A
sprintf( msg_A, "A");
- double latd = cur_fdm_state->get_Latitude() * SGD_RADIANS_TO_DEGREES;
+ double latd = fdm.get_Latitude() * SGD_RADIANS_TO_DEGREES;
if ( latd < 0.0 ) {
latd = -latd;
dir = 'S';
}
deg = (int)latd;
min = (latd - (double)deg) * 60.0 * 100.0;
- sprintf( msg_A, "A%c %02d %04.0f\n", dir, deg, min);
+ sprintf( msg_A, "A%c %02d %04.0f\r\n", dir, deg, min);
// create msg_B
- double lond = cur_fdm_state->get_Longitude() * SGD_RADIANS_TO_DEGREES;
+ double lond = fdm.get_Longitude() * SGD_RADIANS_TO_DEGREES;
if ( lond < 0.0 ) {
lond = -lond;
dir = 'W';
}
deg = (int)lond;
min = (lond - (double)deg) * 60.0 * 100.0;
- sprintf( msg_B, "B%c %03d %04.0f\n", dir, deg, min);
+ sprintf( msg_B, "B%c %03d %04.0f\r\n", dir, deg, min);
// create msg_C
float magdeg = fgGetDouble( "/environment/magnetic-variation-deg" );
double gnd_trk_mag = gnd_trk_true - magdeg;
if ( gnd_trk_mag < 0.0 ) { gnd_trk_mag += 360.0; }
if ( gnd_trk_mag >= 360.0 ) { gnd_trk_mag -= 360.0; }
- sprintf( msg_C, "C%03.0f\n", gnd_trk_mag);
+ sprintf( msg_C, "C%03.0f\r\n", gnd_trk_mag);
// create msg_D
double speed_kt = sqrt( vn*vn + ve*ve ) * SG_FPS_TO_KT;
if ( speed_kt > 999.0 ) {
speed_kt = 999.0;
}
- sprintf( msg_D, "D%03.0f\n", speed_kt);
+ sprintf( msg_D, "D%03.0f\r\n", speed_kt);
// create msg_E (not implemented)
// create msg_G (not implemented)
} else {
dir = 'E';
}
- sprintf( msg_Q, "Q%c%03.0f\n", dir, magdeg * 10.0 );
+ sprintf( msg_Q, "Q%c%03.0f\r\n", dir, magdeg * 10.0 );
// create msg_S (not implemented)
// create msg_T
- sprintf( msg_T, "T---------\n" );
+ sprintf( msg_T, "T---------\r\n" );
// create msg_l (not implemented)
// sentence type 2
- sprintf( msg_type2, "w01%c\n", (char)64 );
+ sprintf( msg_type2, "w01%c\r\n", (char)65 );
// assemble message
string sentence;
sentence += msg_B; // longitude
sentence += msg_C; // ground track
sentence += msg_D; // ground speed (kt)
- // sentence += "E-----\n";
- // sentence += "G-----\n";
- // sentence += "I----\n";
- // sentence += "K-----\n";
- // sentence += "L----\n";
+ // sentence += "E-----\r\n";
+ // sentence += "G-----\r\n";
+ // sentence += "I----\r\n";
+ // sentence += "K-----\r\n";
+ // sentence += "L----\r\n";
sentence += msg_Q; // magvar
- // sentence += "S-----\n";
+ // sentence += "S-----\r\n";
sentence += msg_T; // end of type 1 messages (must be sent)
sentence += msg_type2; // type2 message
- // sentence += "l------\n";
+ // sentence += "l------\r\n";
sentence += '\003'; // ETX
// cout << sentence;
lat *= -1;
}
- cur_fdm_state->set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
+ fdm.set_Latitude( lat * SGD_DEGREES_TO_RADIANS );
SG_LOG( SG_IO, SG_INFO, " lat = " << lat );
// lon val
lon *= -1;
}
- cur_fdm_state->set_Longitude( lon * SGD_DEGREES_TO_RADIANS );
+ 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
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 );
+ fdm.set_V_calibrated_kts( speed );
+ // fdm.set_V_ground_speed( speed );
SG_LOG( SG_IO, SG_INFO, " speed = " << speed );
// heading
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(),
+ 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 == "PGRMZ" ) {
altitude *= SG_METER_TO_FEET;
}
- cur_fdm_state->set_Altitude( altitude );
+ fdm.set_Altitude( altitude );
SG_LOG( SG_IO, SG_INFO, " altitude = " << altitude );