52 char msg_h[32], msg_i[32], msg_j[32], msg_k[32], msg_l[32];
58 double obs =
fgGetDouble(
"/instrumentation/nav[0]/radials/selected-deg" );
59 snprintf( msg_h, 32,
"h%04d\r\n", (
int)(obs*10) );
62 double fuel =
fgGetDouble(
"/consumables/fuel/total-fuel-gals" );
63 if ( fuel > 999.9 ) { fuel = 999.9; }
64 snprintf( msg_i, 32,
"i%04.0f\r\n", fuel*10.0 );
67 double gph =
fgGetDouble(
"/engines/engine[0]/fuel-flow-gph" );
68 gph +=
fgGetDouble(
"/engines/engine[1]/fuel-flow-gph" );
69 gph +=
fgGetDouble(
"/engines/engine[2]/fuel-flow-gph" );
70 gph +=
fgGetDouble(
"/engines/engine[3]/fuel-flow-gph" );
71 if ( gph > 999.9 ) { gph = 999.9; }
72 snprintf( msg_j, 32,
"j%04.0f\r\n", gph*10.0 );
75 snprintf( msg_k, 32,
"k%04d%02d%02d%02d%02d%02d\r\n",
84 alt =
fgGetDouble(
"/instrumentation/pressure-alt-ft" );
85 if ( alt > 99999.0 ) { alt = 99999.0; }
86 snprintf( msg_l, 32,
"l%05.0f\r\n", alt );
103 length = sentence.length();
105 strncpy( buf, sentence.c_str(), length );
113 SG_LOG( SG_IO, SG_INFO,
"parse AV400WSimA message" );
115 std::string msg = buf;
116 msg = msg.substr( 0, length );
117 SG_LOG( SG_IO, SG_INFO,
"entire message = " << msg );
119 std::string ident = msg.substr(0, 1);
120 if ( ident ==
"i" ) {
121 std::string side = msg.substr(1,1);
122 std::string num = msg.substr(2,3);
124 fgSetDouble(
"/instrumentation/av400w/cdi-deflection", 0.0);
127 int pos =
atoi(num.c_str());
131 fgSetDouble(
"/instrumentation/av400w/cdi-deflection",
136 else if ( ident ==
"j" ) {
137 std::string side = msg.substr(1,1);
138 std::string num = msg.substr(2,3);
140 fgSetDouble(
"/instrumentation/av400w/gs-deflection", 0.0);
143 int pos =
atoi(num.c_str());
148 fgSetDouble(
"/instrumentation/av400w/gs-deflection",
149 (
double)pos / 28.57);
153 else if ( ident ==
"k" ) {
154 std::string ind = msg.substr(1,1);
156 fgSetBool(
"/instrumentation/av400w/to-flag",
true);
157 fgSetBool(
"/instrumentation/av400w/from-flag",
false);
159 }
else if ( ind ==
"F" ) {
160 fgSetBool(
"/instrumentation/av400w/to-flag",
false);
161 fgSetBool(
"/instrumentation/av400w/from-flag",
true);
164 fgSetBool(
"/instrumentation/av400w/to-flag",
false);
165 fgSetBool(
"/instrumentation/av400w/from-flag",
false);
170 else if ( ident ==
"S" ) {
171 std::string ind = msg.substr(1,5);
375 std::string data =
"Wx";
376 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/month") & 0xFF ) );
377 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/day") & 0xFF ) );
378 data.push_back( (
char)( (
fgGetInt(
"/sim/time/utc/year") >> 8 ) & 0xFF ) );
379 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/year") & 0xFF ) );
380 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/hour") & 0xFF ) );
381 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/minute") & 0xFF ) );
382 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/second") & 0xFF ) );
383 data.append(
"\x00\x00\x00\x00", 4 );
385 for (
int xctr = 0; xctr < 15; xctr++ ) {
386 data.append(
"\x00\x00\x00\x00\x00\x00\x00\x00", 8 );
388 data.push_back(
'\0' );
391 for ( std::string::const_iterator cli = data.begin(); cli != data.end(); cli++ ) {
395 std::string sentence(
"@@" );
397 sentence.push_back( chksum );
398 sentence +=
"\x0D\n";
401 length = sentence.length();
403 for ( std::string::const_iterator cli = sentence.begin(); cli != sentence.end(); cli++ ) {
416 std::string data =
"Wt";
417 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/month") & 0xFF ) );
418 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/day") & 0xFF ) );
419 data.push_back( (
char)( (
fgGetInt(
"/sim/time/utc/year") >> 8 ) & 0xFF ) );
420 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/year") & 0xFF ) );
421 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/hour") & 0xFF ) );
422 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/minute") & 0xFF ) );
423 data.push_back( (
char)(
fgGetInt(
"/sim/time/utc/second") & 0xFF ) );
424 data.append(
"\x00\x00\x00\x00", 4 );
427 double latd = fdm->get_Latitude() * SGD_RADIANS_TO_DEGREES;
428 latd *= DEG_TO_MILLIARCSECS;
430 data.push_back( (
char)( (
latitude >> 24 ) & 0xFF ) );
431 data.push_back( (
char)( (
latitude >> 16 ) & 0xFF ) );
432 data.push_back( (
char)( (
latitude >> 8 ) & 0xFF ) );
433 data.push_back( (
char)(
latitude & 0xFF ) );
436 double lond = fdm->get_Longitude() * SGD_RADIANS_TO_DEGREES;
437 lond *= DEG_TO_MILLIARCSECS;
439 data.push_back( (
char)( (
longitude >> 24 ) & 0xFF ) );
440 data.push_back( (
char)( (
longitude >> 16 ) & 0xFF ) );
441 data.push_back( (
char)( (
longitude >> 8 ) & 0xFF ) );
442 data.push_back( (
char)(
longitude & 0xFF ) );
446 double alt = fdm->get_Altitude();
447 if ( alt > 99999.0 ) { alt = 99999.0; }
450 alt *= SG_FEET_TO_METER;
451 int altm = (int)( alt * 100.0f );
452 data.push_back( (
char)( ( altm >> 24 ) & 0xFF ) );
453 data.push_back( (
char)( ( altm >> 16 ) & 0xFF ) );
454 data.push_back( (
char)( ( altm >> 8 ) & 0xFF ) );
455 data.push_back( (
char)( altm & 0xFF ) );
458 data.push_back( (
char)( ( altm >> 24 ) & 0xFF ) );
459 data.push_back( (
char)( ( altm >> 16 ) & 0xFF ) );
460 data.push_back( (
char)( ( altm >> 8 ) & 0xFF ) );
461 data.push_back( (
char)( altm & 0xFF ) );
464 double gskt =
fgGetDouble(
"/velocities/groundspeed-kt" );
465 gskt *= SG_KT_TO_MPS;
466 int gsm = (int)( gskt * 100.0f );
467 data.push_back( (
char)( ( gsm >> 8 ) & 0xFF ) );
468 data.push_back( (
char)( gsm & 0xFF ) );
471 double trkdeg =
fgGetDouble(
"/orientation/heading-deg");
472 int hdg = (int)(trkdeg * 10.0f);
473 data.push_back( (
char)( ( hdg >> 8 ) & 0xFF ) );
474 data.push_back( (
char)( hdg & 0xFF ) );
477 double climb_fpm =
fgGetDouble(
"/velocities/vertical-speed-fps" );
478 climb_fpm *= SG_FEET_TO_METER;
479 int vvm = (int)( climb_fpm * 50.0f );
480 data.push_back( (
char)( ( vvm >> 8 ) & 0xFF ) );
481 data.push_back( (
char)( vvm & 0xFF ) );
484 data.push_back(
'\0' );
487 data.append(
"\0\x09\0\x09", 4 );
490 data.push_back(
'\x0D' );
496 for ( std::string::const_iterator cli = data.begin(); cli != data.end(); cli++ ) {
500 std::string sentence(
"@@" );
502 sentence.push_back( chksum );
503 sentence +=
"\x0D\n";
505 length = sentence.length();
507 for ( std::string::const_iterator cli = sentence.begin(); cli != sentence.end(); cli++ ) {
520 std::string data =
"Wm";
523 data.push_back( flight_phase );
527 data.append(
"\0\0", 2 );
534 data.append(
"\0\0", 2 );
541 data.append(
"\x00\x00\x00", 3 );
542 data.append(
"\x00\x01\x00\x01\x00\x01\x00\x01", 8 );
543 data.append(
"\x00\x0F\x00\x0F\x00\x0F", 6 );
546 for ( std::string::const_iterator cli = data.begin(); cli != data.end(); cli++ ) {
550 std::string sentence(
"@@" );
552 sentence.push_back( chksum );
553 sentence +=
"\x0D\n";
555 length = sentence.length();
557 for ( std::string::const_iterator cli = sentence.begin(); cli != sentence.end(); cli++ ) {
569 std::string data =
"Wv";
575 double vn_mps =
fgGetDouble(
"/velocities/speed-north-fps" ) * SG_FEET_TO_METER;
576 int vnm = (int)( vn_mps * 100 );
577 data.push_back( (
char)( ( vnm >> 24 ) & 0xFF ) );
578 data.push_back( (
char)( ( vnm >> 16 ) & 0xFF ) );
579 data.push_back( (
char)( ( vnm >> 8 ) & 0xFF ) );
580 data.push_back( (
char)( vnm & 0xFF ) );
583 double ve_mps =
fgGetDouble(
"/velocities/speed-east-fps" ) * SG_FEET_TO_METER;
584 int vne = (int)( ve_mps * 100 );
585 data.push_back( (
char)( ( vne >> 24 ) & 0xFF ) );
586 data.push_back( (
char)( ( vne >> 16 ) & 0xFF ) );
587 data.push_back( (
char)( ( vne >> 8 ) & 0xFF ) );
588 data.push_back( (
char)( vne & 0xFF ) );
591 double climb_mps =
fgGetDouble(
"/velocities/vertical-speed-fps" ) * SG_FEET_TO_METER;
592 int vnup = (int)( climb_mps * 100 );
593 data.push_back( (
char)( ( vnup >> 24 ) & 0xFF ) );
594 data.push_back( (
char)( ( vnup >> 16 ) & 0xFF ) );
595 data.push_back( (
char)( ( vnup >> 8 ) & 0xFF ) );
596 data.push_back( (
char)( vnup & 0xFF ) );
599 for ( std::string::const_iterator cli = data.begin(); cli != data.end(); cli++ ) {
603 std::string sentence(
"@@" );
605 sentence.push_back( chksum );
606 sentence +=
"\x0D\n";
609 length = sentence.length();
611 for ( std::string::const_iterator cli = sentence.begin(); cli != sentence.end(); cli++ ) {
675 SG_LOG( SG_IO, SG_INFO,
"parse AV400WSimB message" );
679 std::string som = msg.substr(0, 2);
681 SG_LOG( SG_IO, SG_INFO,
"bad start message" );
685 std::string ident = msg.substr(2,2);
687 if ( ident ==
"AH" ) {
689 flight_phase = msg[4];
692 switch( flight_phase ) {
693 case FGAV400WSimB::PHASE_OCEANIC:
700 fgSetBool(
"/instrumentation/av400w/has-gs",
false );
710 fgSetBool(
"/instrumentation/av400w/has-gs",
false );
720 fgSetBool(
"/instrumentation/av400w/has-gs",
false );
730 fgSetBool(
"/instrumentation/av400w/has-gs",
false );
740 fgSetBool(
"/instrumentation/av400w/has-gs",
true );
750 fgSetBool(
"/instrumentation/av400w/has-gs",
true );
760 fgSetBool(
"/instrumentation/av400w/has-gs",
false );
766 else if ( ident ==
"AI" ) {
768 hal = msg.substr(4,2);
772 else if ( ident ==
"Cj" ) {
778 else if ( ident ==
"WA" ) {
780 sbas_sel = msg.substr( 5, 2 );
785 else if ( ident ==
"Wd" ) {
787 val = msg.substr( 4, 2 );
791 else if ( ident ==
"WY" ) {
795 std::string unkmsg = msg.substr( 0, 4 );
796 printf(
"parse_message unknown: %s\n", unkmsg.c_str() );
840 while ( ( templen = io->read( readbuf, 1 ) ) == 1 ) {
841 if ( !som1 && !som2 ) {
842 if ( *readbuf ==
'@' ) {
850 if ( *readbuf ==
'@' ) {
858 else if ( som1 && som2 ) {
859 if ( *readbuf ==
'\n' && !gotCr ) {
862 else if ( *readbuf ==
'\n' && gotCr ) {
870 *bufptr++ = *readbuf;
873 if ( gotCr && gotLf ) {
888 if ( ! io->write( buf, length ) ) {
889 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
890 printf(
"Error sending HostID\n" );
896 else if ( req_sbas ) {
898 if ( ! io->write( buf, length ) ) {
899 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
900 printf(
"Error sending SBAS\n" );
909 if ( ! io->write( buf, length ) ) {
910 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
911 printf(
"Error writing hz message\n" );
917 if ( ! io->write( buf, length ) ) {
918 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
919 printf(
"Error writing hz message\n" );
925 if ( ! io->write( buf, length ) ) {
926 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
927 printf(
"Error writing hz message\n" );
933 if ( hz2 > 0 && ( hz2count % hz2cycles == 0 ) ) {
936 if ( ! io->write( buf, length ) ) {
937 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
938 printf(
"Error writing hz2 message\n" );
944 if ( ! io->write( buf, length ) ) {
945 SG_LOG( SG_IO, SG_WARN,
"Error writing data." );
946 printf(
"Error writing hz2 message\n" );
961 while ( ( templen = io->read( readbuf, 1 ) ) == 1 ) {
962 if ( !som1 && !som2 ) {
963 if ( *readbuf ==
'@' ) {
971 if ( *readbuf ==
'@' ) {
979 else if ( som1 && som2 ) {
980 if ( *readbuf ==
'\n' && !gotCr ) {
983 else if ( *readbuf ==
'\n' && gotCr ) {
991 *bufptr++ = *readbuf;
994 if ( gotCr && gotLf ) {
1012 if ( outputctr % 10 == 0 ) {