Initial revisions.
This commit is contained in:
parent
67defdcf2f
commit
2c4534b7e8
2 changed files with 156 additions and 0 deletions
87
scripts/perl/autopilot/flyplan.pl
Executable file
87
scripts/perl/autopilot/flyplan.pl
Executable file
|
@ -0,0 +1,87 @@
|
||||||
|
#!/usr/bin/perl
|
||||||
|
#
|
||||||
|
# Written by Curtis L. Olson, started January 2003
|
||||||
|
# - there is no warrantee
|
||||||
|
# - released to the public domain
|
||||||
|
|
||||||
|
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;
|
||||||
|
}
|
69
scripts/perl/autopilot/telnet.pl
Normal file
69
scripts/perl/autopilot/telnet.pl
Normal file
|
@ -0,0 +1,69 @@
|
||||||
|
#!/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 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 ... " . $timeout . "\n";
|
||||||
|
sleep(1);
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return 1; # make perl happy
|
Loading…
Reference in a new issue