44 char msg_a[32], msg_b[32], msg_c[32], msg_d[32], msg_e[32];
45 char msg_f[32], msg_h[32], msg_i[32], msg_j[32], msg_k[32], msg_l[32], msg_r[32];
53 double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
61 min = (latd - (double)deg) * 60.0 * 100.0;
62 snprintf( msg_a, 32,
"a%c %03d %04.0f\r\n", dir, deg,
min);
65 double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
73 min = (lond - (double)deg) * 60.0 * 100.0;
74 snprintf( msg_b, 32,
"b%c %03d %04.0f\r\n", dir, deg,
min);
77 double alt = fdm->get_Altitude();
78 if ( alt > 99999.0 ) { alt = 99999.0; }
79 snprintf( msg_c, 32,
"c%05.0f\r\n", alt );
82 double ve_kts =
fgGetDouble(
"/velocities/speed-east-fps" ) * SG_FPS_TO_KT;
89 if ( ve_kts > 999.0 ) { ve_kts = 999.0; }
90 snprintf( msg_d, 32,
"d%c%03.0f\r\n", dir, ve_kts );
93 double vn_kts =
fgGetDouble(
"/velocities/speed-north-fps" ) * SG_FPS_TO_KT;
100 if ( vn_kts > 999.0 ) { vn_kts = 999.0; }
101 snprintf( msg_e, 32,
"e%c%03.0f\r\n", dir, vn_kts );
104 double climb_fpm =
fgGetDouble(
"/velocities/vertical-speed-fps" ) * 60;
105 if ( climb_fpm < 0.0 ) {
106 climb_fpm = -climb_fpm;
111 if ( climb_fpm > 9999.0 ) { climb_fpm = 9999.0; }
112 snprintf( msg_f, 32,
"f%c%04.0f\r\n", dir, climb_fpm );
115 double obs =
fgGetDouble(
"/instrumentation/nav[0]/radials/selected-deg" );
116 snprintf( msg_h,
sizeof(msg_h),
"h%04d\r\n", (
int)(obs*10) );
119 double fuel =
fgGetDouble(
"/consumables/fuel/total-fuel-gals" );
120 if ( fuel > 999.9 ) { fuel = 999.9; }
121 snprintf( msg_i,
sizeof(msg_i),
"i%04.0f\r\n", fuel*10.0 );
124 double gph =
fgGetDouble(
"/engines/engine[0]/fuel-flow-gph" );
125 gph +=
fgGetDouble(
"/engines/engine[1]/fuel-flow-gph" );
126 gph +=
fgGetDouble(
"/engines/engine[2]/fuel-flow-gph" );
127 gph +=
fgGetDouble(
"/engines/engine[3]/fuel-flow-gph" );
128 if ( gph > 999.9 ) { gph = 999.9; }
129 snprintf( msg_j, 32,
"j%04.0f\r\n", gph*10.0 );
132 snprintf( msg_k, 32,
"k%04d%02d%02d%02d%02d%02d\r\n",
138 fgGetInt(
"/sim/time/utc/second") );
141 alt =
fgGetDouble(
"/instrumentation/pressure-alt-ft" );
142 if ( alt > 99999.0 ) { alt = 99999.0; }
143 snprintf( msg_l, 32,
"l%05.0f\r\n", alt );
146 snprintf( msg_r, 32,
"rA\r\n" );
149 snprintf( msg_type2, 256,
"w01%c\r\n", (
char)65 );
152 std::string sentence;
166 sentence += msg_type2;
170 length = sentence.length();
172 strncpy( buf, sentence.c_str(), length );
180 SG_LOG( SG_IO, SG_INFO,
"parse AV400Sim message" );
182 std::string msg = buf;
183 msg = msg.substr( 0, length );
184 SG_LOG( SG_IO, SG_INFO,
"entire message = " << msg );
186 std::string ident = msg.substr(0, 1);
187 if ( ident ==
"i" ) {
188 std::string side = msg.substr(1,1);
189 std::string num = msg.substr(2,3);
191 fgSetDouble(
"/instrumentation/gps/cdi-deflection", 0.0);
193 int pos =
atoi(num.c_str());
199 fgSetBool(
"/instrumentation/gps/has-gs",
false);
201 }
else if ( ident ==
"k" ) {
202 std::string ind = msg.substr(1,1);
204 fgSetBool(
"/instrumentation/gps/to-flag",
true);
205 fgSetBool(
"/instrumentation/gps/from-flag",
false);
206 }
else if ( ind ==
"F" ) {
207 fgSetBool(
"/instrumentation/gps/to-flag",
false);
208 fgSetBool(
"/instrumentation/gps/from-flag",
true);
210 fgSetBool(
"/instrumentation/gps/to-flag",
false);
211 fgSetBool(
"/instrumentation/gps/from-flag",
false);