line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::GPSD::Server::Fake::Track; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
=pod |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
=head1 NAME |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
Net::GPSD::Server::Fake::Track - Provides a linear feed for the GPSD Daemon. |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 SYNOPSIS |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
use Net::GPSD::Server::Fake; |
12
|
|
|
|
|
|
|
use Net::GPSD::Server::Fake::Track; |
13
|
|
|
|
|
|
|
my $server=Net::GPSD::Server::Fake->new(); |
14
|
|
|
|
|
|
|
my $provider=Net::GPSD::Server::Fake::Track->new(lat=>38.865826, |
15
|
|
|
|
|
|
|
lon=>-77.108574, |
16
|
|
|
|
|
|
|
speed=>25, |
17
|
|
|
|
|
|
|
heading=>45.3, |
18
|
|
|
|
|
|
|
alt=>23.4, |
19
|
|
|
|
|
|
|
tle=>$filename); |
20
|
|
|
|
|
|
|
$server->start($provider); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 DESCRIPTION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=cut |
25
|
|
|
|
|
|
|
|
26
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
27
|
1
|
|
|
1
|
|
6
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
44
|
|
28
|
1
|
|
|
1
|
|
488
|
use GPS::SpaceTrack; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
use Geo::Forward; |
30
|
|
|
|
|
|
|
use Net::GPSD::Point; |
31
|
|
|
|
|
|
|
use Net::GPSD::Satellite; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
$VERSION = sprintf("%d.%02d", q{Revision: 0.16} =~ /(\d+)\.(\d+)/); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 CONSTRUCTOR |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head2 new |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns a new provider that can be passed to Net::GPSD::Server::Fake. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
my $provider=Net::GPSD::Server::Fake::Track->new(); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=cut |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
sub new { |
46
|
|
|
|
|
|
|
my $this = shift(); |
47
|
|
|
|
|
|
|
my $class = ref($this) || $this; |
48
|
|
|
|
|
|
|
my $self = {}; |
49
|
|
|
|
|
|
|
bless $self, $class; |
50
|
|
|
|
|
|
|
$self->initialize(@_); |
51
|
|
|
|
|
|
|
return $self; |
52
|
|
|
|
|
|
|
} |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=head1 METHODS |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=cut |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub initialize { |
59
|
|
|
|
|
|
|
my $self = shift(); |
60
|
|
|
|
|
|
|
my %param = @_; |
61
|
|
|
|
|
|
|
$self->{'lat'} =$param{'lat'} || 39.5; |
62
|
|
|
|
|
|
|
$self->{'lon'} =$param{'lon'} || -77.5; |
63
|
|
|
|
|
|
|
$self->{'speed'} =$param{'speed'} || 20; |
64
|
|
|
|
|
|
|
$self->{'heading'}=$param{'heading'} || 0; |
65
|
|
|
|
|
|
|
$self->{'alt'} =$param{'alt'} || 0; |
66
|
|
|
|
|
|
|
$self->{'tlefile'}=$param{'tlefile'}; |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=head2 tle |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Method to create and retrieve the TLE object. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub tle { |
76
|
|
|
|
|
|
|
my $self=shift(); |
77
|
|
|
|
|
|
|
unless (defined($self->{'tle'})) { |
78
|
|
|
|
|
|
|
$self->{'tle'}=GPS::SpaceTrack->new(filename=>$self->{'tlefile'}) |
79
|
|
|
|
|
|
|
|| die("Error: Cannot create GPS::SpaceTrack object."); |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
return $self->{'tle'}; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head2 get |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
Returns a Net::GPSD::Point object |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
my $point=$obj->get; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub get { |
93
|
|
|
|
|
|
|
my $self=shift(); |
94
|
|
|
|
|
|
|
my $time=shift(); |
95
|
|
|
|
|
|
|
my $pt0=shift(); |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $object = Geo::Forward->new(); |
98
|
|
|
|
|
|
|
my $lat; |
99
|
|
|
|
|
|
|
my $lon; |
100
|
|
|
|
|
|
|
my $faz; |
101
|
|
|
|
|
|
|
my $baz; |
102
|
|
|
|
|
|
|
my $speed; |
103
|
|
|
|
|
|
|
my $lasttime; |
104
|
|
|
|
|
|
|
if (ref($pt0) eq "Net::GPSD::Point") { |
105
|
|
|
|
|
|
|
$lat=$pt0->lat; |
106
|
|
|
|
|
|
|
$lon=$pt0->lon; |
107
|
|
|
|
|
|
|
$faz=$pt0->heading; |
108
|
|
|
|
|
|
|
$speed=$pt0->speed; |
109
|
|
|
|
|
|
|
$lasttime=$pt0->time; |
110
|
|
|
|
|
|
|
} else { |
111
|
|
|
|
|
|
|
$lat=$self->{'lat'}; |
112
|
|
|
|
|
|
|
$lon=$self->{'lon'}; |
113
|
|
|
|
|
|
|
$faz=$self->{'heading'}; |
114
|
|
|
|
|
|
|
$speed=$self->{'speed'}; |
115
|
|
|
|
|
|
|
$lasttime=undef(); |
116
|
|
|
|
|
|
|
} |
117
|
|
|
|
|
|
|
if (defined $lasttime) { |
118
|
|
|
|
|
|
|
my $dist=$speed * ($time-$lasttime); |
119
|
|
|
|
|
|
|
($lat,$lon,$baz)=$object->forward($lat,$lon,$faz,$dist); |
120
|
|
|
|
|
|
|
#print "Heading: $faz\n"; |
121
|
|
|
|
|
|
|
$faz=$baz-180; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
my $point=Net::GPSD::Point->new(); |
124
|
|
|
|
|
|
|
$point->tag("FAKE"); |
125
|
|
|
|
|
|
|
$point->time($time); |
126
|
|
|
|
|
|
|
$point->errortime(0.001); |
127
|
|
|
|
|
|
|
$point->lat($lat); |
128
|
|
|
|
|
|
|
$point->lon($lon); |
129
|
|
|
|
|
|
|
$point->speed($speed); |
130
|
|
|
|
|
|
|
#print ", FAZ: $faz"; |
131
|
|
|
|
|
|
|
$point->heading($faz); |
132
|
|
|
|
|
|
|
$point->alt($self->{'alt'}); |
133
|
|
|
|
|
|
|
$point->mode(3); |
134
|
|
|
|
|
|
|
$point->status(1); |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
return $point; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 getsatellitelist |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns a list of Net::GPSD::Satellite objects |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my @list=$obj->getsatellitelist($point); |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=cut |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub getsatellitelist { |
149
|
|
|
|
|
|
|
my $self=shift(); |
150
|
|
|
|
|
|
|
my $point=shift(); |
151
|
|
|
|
|
|
|
my $obj=$self->tle; |
152
|
|
|
|
|
|
|
if (defined $obj) { |
153
|
|
|
|
|
|
|
my $lat=$point->lat; |
154
|
|
|
|
|
|
|
my $lon=$point->lon; |
155
|
|
|
|
|
|
|
my $alt=$point->alt||0; |
156
|
|
|
|
|
|
|
my $time=$point->time; |
157
|
|
|
|
|
|
|
#print "Lat => $lat, Lon => $lon, ALT => $alt, Time => $time\n"; |
158
|
|
|
|
|
|
|
my @list=grep {$_->snr > 0} $obj->getsatellitelist({lat=>$lat, lon=>$lon, |
159
|
|
|
|
|
|
|
alt=>$alt, time=>$time}); |
160
|
|
|
|
|
|
|
pop @list until scalar(@list) <= 12; |
161
|
|
|
|
|
|
|
return wantarray ? @list : \@list; |
162
|
|
|
|
|
|
|
} else { |
163
|
|
|
|
|
|
|
my $obj=Net::GPSD::Satellite->new(0,0,0,0,0); |
164
|
|
|
|
|
|
|
return wantarray ? ($obj) : [$obj]; |
165
|
|
|
|
|
|
|
} |
166
|
|
|
|
|
|
|
} |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
1; |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
__END__ |