line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
16
|
|
|
16
|
|
53864
|
use utf8; |
|
16
|
|
|
|
|
25
|
|
|
16
|
|
|
|
|
78
|
|
2
|
16
|
|
|
16
|
|
367
|
use strict; |
|
16
|
|
|
|
|
21
|
|
|
16
|
|
|
|
|
218
|
|
3
|
16
|
|
|
16
|
|
50
|
use warnings; |
|
16
|
|
|
|
|
18
|
|
|
16
|
|
|
|
|
448
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Net::EGTS::Util; |
6
|
16
|
|
|
16
|
|
57
|
use base qw(Exporter); |
|
16
|
|
|
|
|
18
|
|
|
16
|
|
|
|
|
1584
|
|
7
|
|
|
|
|
|
|
|
8
|
16
|
|
|
16
|
|
72
|
use Carp; |
|
16
|
|
|
|
|
26
|
|
|
16
|
|
|
|
|
707
|
|
9
|
16
|
|
|
16
|
|
5683
|
use Digest::CRC qw(); |
|
16
|
|
|
|
|
29875
|
|
|
16
|
|
|
|
|
303
|
|
10
|
16
|
|
|
16
|
|
5559
|
use Date::Parse qw(); |
|
16
|
|
|
|
|
88651
|
|
|
16
|
|
|
|
|
428
|
|
11
|
16
|
|
|
16
|
|
2663
|
use List::MoreUtils qw(natatime any); |
|
16
|
|
|
|
|
54732
|
|
|
16
|
|
|
|
|
98
|
|
12
|
16
|
|
|
16
|
|
16431
|
use POSIX qw(); |
|
16
|
|
|
|
|
76065
|
|
|
16
|
|
|
|
|
667
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our @EXPORT = qw( |
15
|
|
|
|
|
|
|
crc8 crc16 |
16
|
|
|
|
|
|
|
str2time time2new new2time strftime |
17
|
|
|
|
|
|
|
dumper_bitstring |
18
|
|
|
|
|
|
|
usize |
19
|
|
|
|
|
|
|
lat2mod mod2lat |
20
|
|
|
|
|
|
|
lon2mod mod2lon |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
16
|
|
|
16
|
|
95
|
use constant TIMESTAMP_20100101_000000_UTC => 1262304000; |
|
16
|
|
|
|
|
19
|
|
|
16
|
|
|
|
|
940
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=head2 crc8 $bytes |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
CRC8 with EGTS customization |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=cut |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub crc8($) { |
32
|
16
|
|
|
16
|
|
5622
|
use bytes; |
|
16
|
|
|
|
|
183
|
|
|
16
|
|
|
|
|
76
|
|
33
|
23
|
|
|
23
|
1
|
128
|
my $ctx = Digest::CRC->new( |
34
|
|
|
|
|
|
|
width => 8, |
35
|
|
|
|
|
|
|
poly => 0x31, |
36
|
|
|
|
|
|
|
init => 0xff, |
37
|
|
|
|
|
|
|
xorout => 0x00, |
38
|
|
|
|
|
|
|
check => 0xf7, |
39
|
|
|
|
|
|
|
); |
40
|
23
|
|
|
|
|
1682
|
$ctx->add($_[0]); |
41
|
23
|
|
|
|
|
200
|
return $ctx->digest; |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head2 crc16 $bytes |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
CRC16 with EGTS customization |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub crc16($) { |
51
|
16
|
|
|
16
|
|
1359
|
use bytes; |
|
16
|
|
|
|
|
31
|
|
|
16
|
|
|
|
|
50
|
|
52
|
16
|
|
|
16
|
1
|
52
|
my $ctx = Digest::CRC->new( |
53
|
|
|
|
|
|
|
width => 16, |
54
|
|
|
|
|
|
|
poly => 0x1021, |
55
|
|
|
|
|
|
|
init => 0xffff, |
56
|
|
|
|
|
|
|
xorout => 0x0000, |
57
|
|
|
|
|
|
|
check => 0x29b1, |
58
|
|
|
|
|
|
|
); |
59
|
16
|
|
|
|
|
940
|
$ctx->add($_[0]); |
60
|
16
|
|
|
|
|
92
|
return $ctx->digest; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head2 strftime $format, time |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
Return formatted string. |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=cut |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub strftime { |
70
|
1
|
|
|
1
|
1
|
64
|
POSIX::strftime @_; |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=head2 str2time $str |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
Return timestamp from any time format |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=cut |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
sub str2time($) { |
80
|
4
|
50
|
|
4
|
1
|
11
|
return undef unless defined $_[0]; |
81
|
4
|
50
|
|
|
|
8
|
return undef unless length $_[0]; |
82
|
4
|
50
|
|
|
|
19
|
return $_[0] if $_[0] =~ m{^\d+$}; |
83
|
4
|
|
|
|
|
18
|
return Date::Parse::str2time( $_[0] ); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 time2new [$time] |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Return time from 2010 instead of 1970 |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=cut |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
sub time2new(;$) { |
93
|
7
|
|
|
7
|
1
|
1024
|
my ($time) = @_; |
94
|
7
|
|
66
|
|
|
27
|
$time //= time; |
95
|
7
|
|
|
|
|
20
|
return ($time - TIMESTAMP_20100101_000000_UTC); |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 new2time [$time] |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Return time from 1970 instead of 2010 |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=cut |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
sub new2time($) { |
105
|
1
|
|
|
1
|
1
|
4
|
my ($time) = @_; |
106
|
1
|
|
|
|
|
8
|
return ($time + TIMESTAMP_20100101_000000_UTC); |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=head2 dumper_bitstring $bin, [$size] |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Return bitstring from I<$bin> chanked by I<$size> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub dumper_bitstring($;$) { |
116
|
6
|
|
|
6
|
1
|
13
|
my ($bin, $size) = @_; |
117
|
6
|
|
|
|
|
87
|
my @bytes = ((unpack('B*', $bin)) =~ m{.{8}}g); |
118
|
6
|
|
50
|
|
|
46
|
my $it = natatime( ($size || 4), @bytes ); |
119
|
6
|
|
|
|
|
9
|
my @chunks; |
120
|
6
|
|
|
|
|
18
|
while (my @vals = $it->()) { |
121
|
44
|
|
|
|
|
139
|
push @chunks, join ' ', @vals; |
122
|
|
|
|
|
|
|
} |
123
|
6
|
|
|
|
|
50
|
return join "\n", @chunks; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=head2 usize $mask |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
Return size in bytes of pack/unpack mask |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=cut |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
sub usize($) { |
133
|
514
|
|
|
514
|
1
|
2061
|
my ($mask) = @_; |
134
|
16
|
|
|
16
|
|
4984
|
use bytes; |
|
16
|
|
|
|
|
27
|
|
|
16
|
|
|
|
|
44
|
|
135
|
514
|
50
|
|
|
|
613
|
die 'Unknown "*" length' if $mask =~ m{^\w\*$}; |
136
|
514
|
|
|
|
|
1371
|
return length pack $mask => 0; |
137
|
|
|
|
|
|
|
} |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head2 lat2mod $latitude |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Module from latitude |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=cut |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
sub lat2mod($) { |
146
|
4
|
|
|
4
|
1
|
2208
|
return int( abs( $_[0] ) / 90 * 0xffffffff ); |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head2 mod2lat $module, $sign |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Latitude from module and sign |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=cut |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
sub mod2lat($$) { |
156
|
3
|
|
|
3
|
1
|
2034
|
my ($module, $sign) = @_; |
157
|
3
|
100
|
|
|
|
48
|
return $_[0] / 0xffffffff * 90 * ($sign ? -1 : 1); |
158
|
|
|
|
|
|
|
} |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 lon2mod $longitude |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
Module from longitude |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub lon2mod($) { |
167
|
4
|
|
|
4
|
1
|
2080
|
return int( abs( $_[0] ) / 180 * 0xffffffff ); |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 mod2lon $module, $sign |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
Longitude from module and sign. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
sub mod2lon($$) { |
177
|
3
|
|
|
3
|
1
|
2120
|
my ($module, $sign) = @_; |
178
|
3
|
100
|
|
|
|
34
|
return $_[0] / 0xffffffff * 180 * ($sign ? -1 : 1); |
179
|
|
|
|
|
|
|
} |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
1; |