Melchior FRANZ:
Yesterday night it occurred to me that the current handling of missing METAR strings isn't good enough: - in case of missing METAR strings, don't re-send the last successful string, but the last successful string sent to *this* client. (If one client is running in virtual December, it won't be happy about dropped in summer weather.) - fix a bug that allowed -vc notation (options -v and -c), but broke a lot of other notations (-b/var/tmp). Only -v can now be accumulated again, as in -vvvv.
This commit is contained in:
parent
964349e401
commit
5a5b67bab1
2 changed files with 14 additions and 16 deletions
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
|
|
||||||
metarproxy is a caching proxy server for METAR data strings written in
|
metarproxy is a caching proxy server for METAR data strings written in
|
||||||
Perl. It can be used from the FlightGear flight simulator to:
|
Perl. It can be used to:
|
||||||
|
|
||||||
- provide METAR data for machines without internet connection
|
- provide METAR data for machines without internet connection
|
||||||
- centralize METAR fetching: one machine in a network runs the proxy, all
|
- centralize METAR fetching: one machine in a network runs the proxy, all
|
||||||
|
@ -129,7 +129,7 @@ Ranges are allowed, too:
|
||||||
$ metarproxy --download 0-2 ... download first three hours after
|
$ metarproxy --download 0-2 ... download first three hours after
|
||||||
midnight GMT
|
midnight GMT
|
||||||
|
|
||||||
These three methods can be use in combination:
|
These three methods can be used in combination:
|
||||||
|
|
||||||
$ metarproxy --download 6h 0-2 4
|
$ metarproxy --download 6h 0-2 4
|
||||||
|
|
||||||
|
@ -176,7 +176,7 @@ stored in the cache. Additionally, you can specify one or more files
|
||||||
with station IDs:
|
with station IDs:
|
||||||
|
|
||||||
$ metarproxy --record --file=$FG_HOME/station-list
|
$ metarproxy --record --file=$FG_HOME/station-list
|
||||||
$ metarproxy --record EDDM --file=tmp/Austria --file=/tmp/Hungary
|
$ metarproxy --record EDDM --file=/tmp/Austria --file=/tmp/Hungary
|
||||||
|
|
||||||
These files simply contain station IDs separated by spaces in one
|
These files simply contain station IDs separated by spaces in one
|
||||||
or more lines:
|
or more lines:
|
||||||
|
@ -232,7 +232,8 @@ All you need to do is point FlightGear to the metar proxy and let
|
||||||
it run at a simulated time for which you actually have cached METAR
|
it run at a simulated time for which you actually have cached METAR
|
||||||
data:
|
data:
|
||||||
|
|
||||||
$ fgfs --proxy=localhost:5509 --start-date-lat=2005:01:12:12:00:00
|
$ fgfs --enable-real-weather-fetch --proxy=localhost:5509 \
|
||||||
|
--start-date-lat=2005:01:12:12:00:00
|
||||||
|
|
||||||
FlightGear will then fetch the metar data from the proxy as if it
|
FlightGear will then fetch the metar data from the proxy as if it
|
||||||
were weather.noaa.gov. If no appropriate data set is found at all,
|
were weather.noaa.gov. If no appropriate data set is found at all,
|
||||||
|
|
|
@ -113,12 +113,6 @@ sub parse_options()
|
||||||
while (1) {
|
while (1) {
|
||||||
$_ = $ARGV[0];
|
$_ = $ARGV[0];
|
||||||
defined $_ or last;
|
defined $_ or last;
|
||||||
# dissolve glued together short options (e.g. -cvv)
|
|
||||||
if (/^-([^-]{2,})$/) {
|
|
||||||
shift @ARGV;
|
|
||||||
map { unshift @ARGV, "-$_" } split //, $1;
|
|
||||||
next;
|
|
||||||
}
|
|
||||||
if (!/^-/) {
|
if (!/^-/) {
|
||||||
push @ITEMS, $_;
|
push @ITEMS, $_;
|
||||||
} elsif (/^(-d|--download)$/) {
|
} elsif (/^(-d|--download)$/) {
|
||||||
|
@ -148,8 +142,10 @@ sub parse_options()
|
||||||
$PROXY = &argument($2, $4);
|
$PROXY = &argument($2, $4);
|
||||||
defined $PROXY or &fatal("--proxy option lacks <host> definition");
|
defined $PROXY or &fatal("--proxy option lacks <host> definition");
|
||||||
&log($BULK, "set option --proxy: '$PROXY'");
|
&log($BULK, "set option --proxy: '$PROXY'");
|
||||||
} elsif (/^(-v|--verbose)$/) {
|
} elsif (/^--verbose$/) {
|
||||||
$VERBOSITY++;
|
$VERBOSITY++;
|
||||||
|
} elsif (/^-(v+)$/) {
|
||||||
|
$VERBOSITY += length($1);
|
||||||
} elsif (/^(-q|--quiet)$/) {
|
} elsif (/^(-q|--quiet)$/) {
|
||||||
$VERBOSITY = 0;
|
$VERBOSITY = 0;
|
||||||
} elsif (/^(-h|--help)$/) {
|
} elsif (/^(-h|--help)$/) {
|
||||||
|
@ -390,6 +386,7 @@ sub serve()
|
||||||
my $server = IO::Socket::INET->new(Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1);
|
my $server = IO::Socket::INET->new(Proto => 'tcp', LocalPort => $PORT, Listen => SOMAXCONN, Reuse => 1);
|
||||||
$server or &fatal("cannot setup server ($!)");
|
$server or &fatal("cannot setup server ($!)");
|
||||||
&log($BULK, "server $0 accepting clients on port $PORT");
|
&log($BULK, "server $0 accepting clients on port $PORT");
|
||||||
|
my %last_metar;
|
||||||
|
|
||||||
while (my $client = $server->accept()) {
|
while (my $client = $server->accept()) {
|
||||||
$client->autoflush(1);
|
$client->autoflush(1);
|
||||||
|
@ -425,9 +422,9 @@ sub serve()
|
||||||
if ($age <= $METAR_MAX_AGE) {
|
if ($age <= $METAR_MAX_AGE) {
|
||||||
&log($BULK, "found (" . int($age / 60) . " min old)");
|
&log($BULK, "found (" . int($age / 60) . " min old)");
|
||||||
$metar =~ s/\s*$//s;
|
$metar =~ s/\s*$//s;
|
||||||
$METAR_DEFAULT = $metar;
|
$last_metar{$addr} = $metar;
|
||||||
$METAR_DEFAULT =~ s/.*\015?\012[A-Z0-9]{4}\s+[0-9]{6}Z\s+//s;
|
$last_metar{$addr} =~ s/.*\015?\012[A-Z0-9]{4}\s+[0-9]{6}Z\s+//s;
|
||||||
&log($DEBUG, "setting default to '$METAR_DEFAULT'");
|
&log($DEBUG, "setting default for [$addr] to '$last_metar{$addr}'");
|
||||||
$metar =~ s/\015?\012/\015\012/g;
|
$metar =~ s/\015?\012/\015\012/g;
|
||||||
} else {
|
} else {
|
||||||
&log($INFO, "found, but too old (" . int($age / 60) . " min)");
|
&log($INFO, "found, but too old (" . int($age / 60) . " min)");
|
||||||
|
@ -441,8 +438,8 @@ sub serve()
|
||||||
&log($INFO, "sending last successful data again");
|
&log($INFO, "sending last successful data again");
|
||||||
$metar = sprintf "%04d/%02d/%02d %02d:%02d\015\012",
|
$metar = sprintf "%04d/%02d/%02d %02d:%02d\015\012",
|
||||||
$year, $mon, $day, $hour, $min;
|
$year, $mon, $day, $hour, $min;
|
||||||
$metar .= sprintf "$icao %02d%02d%02dZ $METAR_DEFAULT",
|
$metar .= sprintf "$icao %02d%02d%02dZ ", $day, $hour, $min;
|
||||||
$day, $hour, $min;
|
$metar .= $last_metar{$addr} || $METAR_DEFAULT;
|
||||||
}
|
}
|
||||||
print $client "Content-Type: text/plain\015\012"
|
print $client "Content-Type: text/plain\015\012"
|
||||||
. "X-MetarProxy: nasse Maus\015\012"
|
. "X-MetarProxy: nasse Maus\015\012"
|
||||||
|
|
Loading…
Reference in a new issue