TaskStats: simplify margin formula
[xcsoar.git] / tools / AndroidMockLocation.pl
blob0666316312fd8fa9cf3d4cbb8d40b5e1905bc723
1 #!/usr/bin/perl
3 # Send a NMEA dump to the Android emulator.
5 # Example: AndroidMockLocation.pl test.nmea 127.0.0.1:5554
8 use strict;
9 use warnings;
10 require IO::Socket;
12 die "Usage: AndroidMockLocation.pl FILE.nmea HOST:PORT\n"
13 unless @ARGV == 2;
15 my ($path, $address) = @ARGV;
17 open FILE, "<$path" or die "Failed to open $path: $!\n";
19 my $socket = new IO::Socket::INET(PeerAddr => $address);
20 die "Failed to connect to emulator: $!\n" unless defined $socket;
22 $socket->getline;
23 $socket->getline;
25 my $time = '';
26 while (<FILE>) {
27 if (/^\$..GGA,(\d+)/) {
28 my $new_time = $1;
29 unless ($new_time eq $time) {
30 # sleep for a second when the time stamp has been updated
31 sleep 1;
32 $time = $new_time;
34 } elsif (/^\$..RMC,/) {
35 } else {
36 # the Android emulator understands only GPGGA and GPRMC
37 next;
40 my $line = "geo nmea $_";
41 print $line;
42 $socket->syswrite($line) or die $!;
43 my $response = $socket->getline;
44 die $response unless $response =~ /^OK/;