File: reset.pl

package info (click to toggle)
flightgear 0.9.6-1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 9,948 kB
  • ctags: 17,555
  • sloc: cpp: 90,696; ansic: 5,266; sh: 3,488; makefile: 840; perl: 680; python: 106
file content (79 lines) | stat: -rwxr-xr-x 2,002 bytes parent folder | download | duplicates (13)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
#!/usr/bin/perl

require "telnet.pl";

use strict;

my( $airport_id ) = "KSNA";
my( $rwy_no ) = "19R";
my( $reset_sec ) = 300;

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;
}