1
0
Fork 0

Initial revision.

This commit is contained in:
curt 2003-12-19 15:36:54 +00:00
parent 439a9fa1e4
commit cdbfda256e
3 changed files with 254 additions and 0 deletions

View file

@ -0,0 +1,91 @@
#!/usr/bin/perl
#
# Written by Curtis L. Olson, started January 2003
#
# This file is in the Public Domain and comes with no warranty.
#
# $Id$
# ----------------------------------------------------------------------------
use strict;
require "telnet.pl";
my( $server ) = "localhost";
my( $port ) = 5401;
my( $timeout ) = 10;
my( %Route );
$Route{0} = "OAK:116.80:020";
$Route{1} = "OAK:116.80:019:27";
$Route{2} = "SAC:115.20:020";
$Route{3} = "SAC:115.20:080:43";
$Route{4} = "ECA:116.0:209";
my( $i );
foreach $i ( keys(%Route) ) {
&fly_to( $Route{$i} );
}
sub fly_to() {
my( $waypoint ) = shift;
# decode waypoint
my( $id, $freq, $radial, $dist ) = split( /:/, $waypoint );
print "Next way point is $id - $freq\n";
print " Target radial is $radial\n";
if ( $dist ne "" ) {
print " Flying outbound for $dist nm\n";
} else {
print " Flying inbound to station\n";
}
# tune radio and set autopilot
my( $fgfs );
if ( !( $fgfs = &connect($server, $port, $timeout) ) ) {
print "Error: can't open socket\n";
return;
}
&send( $fgfs, "data" ); # switch to raw data mode
set_prop( $fgfs, "/radios/nav[0]/frequencies/selected-mhz", $freq );
set_prop( $fgfs, "/radios/nav[0]/radials/selected-deg", $radial );
set_prop( $fgfs, "/radios/dme/switch-position", "1" );
set_prop( $fgfs, "/autopilot/locks/nav", "true" );
# monitor progress until goal is achieved
my( $done ) = 0;
my( $last_range ) = 9999.0;
while ( !$done ) {
my( $inrange ) = get_prop( $fgfs, "/radios/nav[0]/in-range" );
if ( $inrange eq "false" ) {
print "Warning, VOR not in range, we are lost!\n";
}
my( $cur_range ) = get_prop( $fgfs, "/radios/dme/distance-nm" );
print " range = $cur_range\n";
if ( $dist ne "" ) {
# a target dist is specified so assume we are flying outbound
if ( $cur_range > $dist ) {
$done = 1;
}
} else {
# no target dist is specified, assume we are flying
# inbound to the station
if ( $cur_range < 0.25 && $cur_range > 0.0 ) {
$done = 1;
} elsif ( $last_range < $cur_range ) {
$done = 1;
}
}
$last_range = $cur_range;
# loop once per second
sleep(1);
}
&send( $fgfs, "quit");
close $fgfs;
}

79
scripts/perl/examples/reset.pl Executable file
View file

@ -0,0 +1,79 @@
#!/usr/bin/perl
require "telnet.pl";
use strict;
my( $airport_id ) = "KSNA";
my( $rwy_no ) = "19R";
my( $reset_sec ) = 30;
my( $server ) = "localhost";
my( $port ) = 5401;
my( $timeout ) = 5;
while ( 1 ) {
print "Reseting to $airport_id $rwy_no\n";
reset_position( $airport_id, $rwy_no );
sleep( $reset_sec );
}
sub reset_position {
my( $aptid ) = shift;
my( $rwy ) = shift;
my( $prop, $value );
my( %HASH ) = ();
$HASH{ "/sim/presets/airport-id" } = $aptid;
$HASH{ "/sim/presets/runway" } = $rwy;
$HASH{ "/sim/presets/vor-id" } = "";
$HASH{ "/sim/presets/vor-freq" } = "";
$HASH{ "/sim/presets/ndb-id" } = "";
$HASH{ "/sim/presets/ndb-freq" } = "";
$HASH{ "/sim/presets/fix" } = "";
$HASH{ "/sim/presets/longitude-deg" } = "-9999.0";
$HASH{ "/sim/presets/latitude-deg" } = "-9999.0";
$HASH{ "/sim/presets/offset-distance" } = "";
$HASH{ "/sim/presets/offset-azimuth" } = "";
$HASH{ "/sim/presets/heading-deg" } = "-9999.0";
$HASH{ "/sim/presets/altitude-ft" } = "";
$HASH{ "/sim/presets/glideslope-deg" } = "";
$HASH{ "/sim/presets/airspeed-kt" } = "";
my( $fgfs );
if ( !( $fgfs = &connect($server, $port, $timeout) ) ) {
print "Error: can't open socket\n";
return;
}
&send( $fgfs, "data" ); # switch to raw data mode
foreach $prop ( keys(%HASH) ) {
$value = $HASH{$prop};
# if ( $value eq "" ) {
# $value = 0;
# }
print "setting $prop = $value\n";
&set_prop( $fgfs, $prop, $value );
}
&send( $fgfs, "run presets-commit" );
# set time of day to noon
&send( $fgfs, "run timeofday noon" );
# start the engine
&set_prop( $fgfs, "/controls/engines/engine[0]/magnetos", "3" );
&set_prop( $fgfs, "/controls/engines/engine[0]/starter", "true" );
sleep(2);
&set_prop( $fgfs, "/controls/engines/engine[0]/starter", "false" );
&send( $fgfs, "quit" );
close $fgfs;
}

View file

@ -0,0 +1,84 @@
#!/usr/bin/perl
#
# Written by Curtis L. Olson, started December 2002
# Some code portions courtesy of Melchior FRANZ
#
# This file is in the Public Domain and comes with no warranty.
#
# $Id$
# ----------------------------------------------------------------------------
use IO::Socket;
use strict;
sub my_not() {
my( $val ) = shift;
if ( $val eq "true" ) {
return 0;
} elsif ( $val eq "false" ) {
return 1;
} elsif ( $val eq "" ) {
return 1;
} else {
return 0;
}
}
sub get_prop() {
my( $handle ) = shift;
&send( $handle, "get " . shift );
eof $handle and die "\nconnection closed by host";
$_ = <$handle>;
s/\015?\012$//;
/^-ERR (.*)/ and die "\nfgfs error: $1\n";
return $_;
}
sub set_prop() {
my( $handle ) = shift;
my( $prop ) = shift;
my( $value ) = shift;
&send( $handle, "set $prop $value");
# eof $handle and die "\nconnection closed by host";
}
sub send() {
my( $handle ) = shift;
print $handle shift, "\015\012";
}
sub connect() {
my( $host ) = shift;
my( $port ) = shift;
my( $timeout ) = (shift || 120);
my( $socket );
STDOUT->autoflush(1);
while ($timeout--) {
if ($socket = IO::Socket::INET->new( Proto => 'tcp',
PeerAddr => $host,
PeerPort => $port) )
{
$socket->autoflush(1);
return $socket;
}
print "Attempting to connect to $host ... " . $timeout . "\n";
sleep(1);
}
return 0;
}
return 1; # make perl happy