lib/Net/EGTS/SubRecord/Teledata/PosData.pm

filter: Statementstmt 98.5% 137 / 139 Branchbran 73.9% 34 / 46 Conditioncond 57.1% 4 / 7 MC/DCmcdc 25.0% 1 / 4 Subroutinesub 100% 13 / 13 Podpod n/a totaltotal 90.4% 189 / 209 CC 27 SCAR 21.6
CC
27
Cov
91%
__ANON__
16.7
__ANON__
6.1
__ANON__
3.0
CRAP 8.7
« blib/lib/Net/EGTS/Record.pm ↑ Summary lib/Net/EGTS/Packet.pm »
1 4 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package Net::EGTS::SubRecord::Teledata::PosData;
4 4 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 extends qw(Net::EGTS::SubRecord);
6  
7 4 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 4 ▶use Net::EGTS::Util qw(usize time2new str2time lat2mod lon2mod dumper_bitstring);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use Net::EGTS::Codes;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 =head1 NAME
13  
14 Net::EGTS::SubRecord::Teledata::PosData - subrecord containing telemetry data.
15  
16 =head1 SEE ALSO
17  
18 L<https://zakonbase.ru/content/part/1191925?print=1>
19  
20 =cut
21  
22 # Navigation Time
23 3 ▶has NTM => is => 'rw', isa => 'UINT', default => sub{ time2new };
Subroutine __ANON__: called CC=1 SCAR=0.0
24 # Latitude
25 4 has LAT => is => 'rw', isa => 'UINT';
26 # Longitude
27 4 has LONG => is => 'rw', isa => 'UINT';
28  
29 # Flags:
30 # altitude exists
31 4 has ALTE => is => 'rw', isa => 'BIT1', default => 0;
32 # east/west
33 4 has LOHS => is => 'rw', isa => 'BIT1';
34 # south/nord
35 4 has LAHS => is => 'rw', isa => 'BIT1';
36 # move
37 has MV =>
38 is => 'rw',
39 isa => 'BIT1',
40 lazy => 1,
41 3 ▶ builder => sub { $_[0]->SPD_LO || $_[0]->SPD_HI ? 0x1 : 0x0 },
Subroutine __ANON__: called CC=3 SCAR=11.1
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->SPD_LO || $_[0]->SPD_HI ? : 1 2 3
Condition66%2/3
$_[0]->SPD_LO or $_[0]->SPD_HI
l!l&&r!l&&!r
102
MC/DC50%1/2
$_[0]->SPD_LO or $_[0]->SPD_HI
$_[0]->SPD_LO $_[0]->SPD_HI
Truth table66%2/3
A or B
A= $_[0]->SPD_LOB= $_[0]->SPD_HI
ABresult
1X1
011
000
42 4 ;
43 # from storage
44 4 has BB => is => 'rw', isa => 'BIT1', default => 0;
45 # coordinate system
46 4 has CS => is => 'rw', isa => 'BIT1', default => 0;
47 # 2d/3d
48 4 has FIX => is => 'rw', isa => 'BIT1', default => 1;
49 # valid
50 4 has VLD => is => 'rw', isa => 'BIT1', default => 1;
51  
52 # Speed (lower bits)
53 4 has SPD_LO => is => 'rw', isa => 'BYTE', default => 0;
54 # Direction the Highest bit
55 4 has DIRH => is => 'rw', isa => 'BIT1', default => 0;
56 # Altitude Sign
57 4 has ALTS => is => 'rw', isa => 'BIT1', default => 0;
58 # Speed (highest bits)
59 4 has SPD_HI => is => 'rw', isa => 'BIT6', default => 0;
60  
61 # Direction
62 4 has DIR => is => 'rw', isa => 'BYTE', default => 0;
63 # Odometer
64 4 has ODM => is => 'rw', isa => 'BINARY3', default => 0x000;
65 # Digital Inputs
66 4 has DIN => is => 'rw', isa => 'BIT8', default => 0b00000000;
67 # Source
68 4 has SRC => is => 'rw', isa => 'BYTE', default => EGTS_SRCD_TIMER;
69  
70 # Optional:
71 # Altitude
72 4 has ALT => is => 'rw', isa => 'Maybe[BINARY3]';
73 # Source Data
74 4 has SRCD => is => 'rw', isa => 'Maybe[SHORT]';
75  
76 after 'decode' => sub {
77 3 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
78 3 ▶ die 'SubRecord not EGTS_SR_POS_DATA type'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SRT == 16 0 3 3
79 unless $self->SRT == EGTS_SR_POS_DATA;
80  
81 3 my $bin = $self->SRD;
82 3 $self->NTM( $self->nip(\$bin => 'L') );
83 3 $self->LAT( $self->nip(\$bin => 'L') );
84 3 $self->LONG($self->nip(\$bin => 'L') );
85  
86 3 my $flags = $self->nip(\$bin => 'C');
87 3 $self->ALTE( ($flags & 0b10000000) >> 7 );
88 3 $self->LOHS( ($flags & 0b01000000) >> 6 );
89 3 $self->LAHS( ($flags & 0b00100000) >> 5 );
90 3 $self->MV( ($flags & 0b00010000) >> 4 );
91 3 $self->BB( ($flags & 0b00001000) >> 3 );
92 3 $self->CS( ($flags & 0b00000100) >> 2 );
93 3 $self->FIX( ($flags & 0b00000010) >> 1 );
94 3 $self->VLD( ($flags & 0b00000001) );
95  
96 3 $self->SPD_LO( $self->nip(\$bin => 'C') );
97  
98 3 my $stupid = $self->nip(\$bin => 'C');
99 3 $self->DIRH( ($stupid & 0b10000000) >> 7 );
100 3 $self->ALTS( ($stupid & 0b01000000) >> 6 );
101 3 $self->SPD_HI($stupid & 0b00111111 );
102  
103 3 $self->DIR( $self->nip(\$bin => 'C') );
104 3 $self->ODM( $self->nip(\$bin => 'a3') );
105 3 $self->DIN( $self->nip(\$bin => 'C') );
106 3 $self->SRC( $self->nip(\$bin => 'C') );
107  
108 3 ▶ $self->ALT( $self->nip(\$bin => 'a3') ) if $self->ALTE;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ALTE 0 3 3
109 3 $self->SRCD($self->nip(\$bin => 'S' => length($bin)) );
110 4 };
111  
112  
113 before 'encode' => sub {
114 3 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=6 SCAR=18.0
115 4 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
116  
117 3 ▶ die 'SubRecord not EGTS_SR_POS_DATA type'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->SRT == 16 0 3 3
118 unless $self->SRT == EGTS_SR_POS_DATA;
119  
120 # Pack stupid bits economy
121 3 my $stupid = $self->SPD_HI;
122 3 ▶ $stupid = ($stupid | 0b10000000) if $self->DIRH;
Branch: 1 branch
BranchTrueFalseTotal
if $self->DIRH 1 2 3
123 3 ▶ $stupid = ($stupid | 0b01000000) if $self->ALTS;
Branch: 1 branch
BranchTrueFalseTotal
if $self->ALTS 0 3 3
124  
125 3 my $bin = '';
126 3 $bin .= pack 'L' => $self->NTM;
127 3 $bin .= pack 'L' => $self->LAT;
128 3 $bin .= pack 'L' => $self->LONG;
129 3 $bin .= pack 'B8' => sprintf(
130 '%b%b%b%b%b%b%b%b',
131 $self->ALTE, $self->LOHS, $self->LAHS, $self->MV,
132 $self->BB, $self->CS, $self->FIX, $self->VLD
133 );
134 3 $bin .= pack 'C' => $self->SPD_LO;
135 3 $bin .= pack 'C' => $stupid;
136 3 $bin .= pack 'C' => $self->DIR;
137 3 $bin .= pack 'a3' => substr(pack("L", $self->ODM), 0, 3);
138 3 $bin .= pack 'B8' => $self->DIN;
139 3 $bin .= pack 'C' => $self->SRC;
140 3 ▶ $bin .= pack 'a3' => substr(pack("L", $self->ALT), 0, 3)
Branch: 1 branch
BranchTrueFalseTotal
if $self->ALTE 0 3 3
141 if $self->ALTE;
142 3 ▶ $bin .= pack 'S' => $self->SRCD
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->SRCD 0 3 3
143 if defined $self->SRCD;
144  
145 3 $self->SRD( $bin );
146 4 };
147  
148 around BUILDARGS => sub {
149 6 ▶ my $orig = shift;
Subroutine __ANON__: called CC=16 SCAR=28.1
150 6 my $class = shift;
151  
152 # simple scalar decoding support
153 6 ▶ my $bin = @_ % 2 ? shift : undef;
Branch: 1 branch
BranchTrueFalseTotal
@_ % 2 ? : 1 5 6
154 6 my %opts = @_;
155  
156 # Simple helpers for real data:
157 6 ▶ if( defined( my $time = delete $opts{time} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $time = delete $opts{"time"})) 3 3 6
158 3 $opts{NTM} = time2new str2time $time;
159 }
160  
161 6 ▶ if( defined( my $lat = delete $opts{latitude} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $lat = delete $opts{"latitude"})) 3 3 6
162 3 $opts{LAT} = lat2mod $lat;
163 3 ▶ $opts{LAHS} = $lat > 0 ? 0x0 : 0x1
Branch: 1 branch
BranchTrueFalseTotal
$lat > 0 ? : 3 0 3
164 }
165  
166 6 ▶ if( defined( my $lon = delete $opts{longitude} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $lon = delete $opts{"longitude"})) 3 3 6
167 3 $opts{LONG} = lon2mod $lon;
168 3 ▶ $opts{LOHS} = $lon > 0 ? 0x0 : 0x1
Branch: 1 branch
BranchTrueFalseTotal
$lon > 0 ? : 3 0 3
169 }
170  
171 6 ▶ if( defined( my $direction = delete $opts{direction} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $direction = delete $opts{"direction"})) 1 5 6
172 1 ▶ if( $direction > 255 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($direction > 255) { } 1 0 1
173 1 $opts{DIRH} = 1;
174 1 $opts{DIR} = $direction - 256;
175 } else {
176 0 $opts{DIRH} = 0;
177 0 $opts{DIR} = $direction;
178 }
179 }
180  
181 6 ▶ if( defined( my $dist = delete $opts{dist} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dist = delete $opts{"dist"})) 1 5 6
182 1 ▶ $opts{ODM} = int(($dist // 0) * 10);
Condition50%1/2
$dist // 0
l!l
10
MC/DC0%0/1
$dist // 0
$dist
Truth table50%1/2
A
A= $dist
Aresult
11
00
183 }
184  
185 6 ▶ if( defined( my $avg_speed = delete $opts{avg_speed} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $avg_speed = delete $opts{"avg_speed"})) 1 5 6
186 # Speed rounded to 0.1
187 1 ▶ my $SPD = int(($avg_speed // 0) * 10);
Condition50%1/2
$avg_speed // 0
l!l
10
MC/DC0%0/1
$avg_speed // 0
$avg_speed
Truth table50%1/2
A
A= $avg_speed
Aresult
11
00
188  
189 1 $opts{SPD_LO} = ($SPD & 0x000000ff);
190 1 $opts{SPD_HI} = ($SPD & 0x0000ff00) >> 8;
191 }
192  
193 6 ▶ if( defined( my $order = delete $opts{order} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $order = delete $opts{"order"})) 1 5 6
194 1 ▶ $opts{DIN} = $order ? 0b10000000 : 0b00000000;
Branch: 1 branch
BranchTrueFalseTotal
$order ? : 1 0 1
195 }
196  
197 6 ▶ return $class->$orig( bin => $bin, %opts, SRT => EGTS_SR_POS_DATA ) if $bin;
Branch: 1 branch
BranchTrueFalseTotal
if $bin 1 5 6
198 5 return $class->$orig( %opts, SRT => EGTS_SR_POS_DATA );
199 4 };
200  
201 augment as_debug => sub {
202 4 ▶ my ($self) = @_;
Subroutine __ANON__: called CC=3 SCAR=11.0
203 4 ▶ use bytes;
Subroutine BEGIN: called CC=1 SCAR=0.0
204  
205 4 my @bytes = ((unpack('B*', $self->SRD)) =~ m{.{8}}g);
206  
207 4 my @str;
208 4 push @str => sprintf('NTM: %s %s %s %s', splice @bytes, 0 => usize('L'));
209 4 push @str => sprintf('LAT: %s %s %s %s', splice @bytes, 0 => usize('L'));
210 4 push @str => sprintf('LONG: %s %s %s %s', splice @bytes, 0 => usize('L'));
211  
212 4 push @str => sprintf('FLAGS: %s', splice @bytes, 0 => usize('C'));
213  
214 4 push @str => sprintf('SPD_LO: %s', splice @bytes, 0 => usize('C'));
215 4 push @str => sprintf('SPD_HI: %s', splice @bytes, 0 => usize('C'));
216 4 push @str => sprintf('DIR: %s', splice @bytes, 0 => usize('C'));
217 4 push @str => sprintf('ODM: %s %s %s', splice @bytes, 0 => 3);
218 4 push @str => sprintf('DIN: %s', splice @bytes, 0 => usize('C'));
219 4 push @str => sprintf('SRC: %s', splice @bytes, 0 => usize('C'));
220  
221 4 ▶ push @str => sprintf('ALT: %s %s %s', splice @bytes, 0 => 3)
Branch: 1 branch
BranchTrueFalseTotal
if $self->ALTE 0 4 4
222 if $self->ALTE;
223 4 ▶ push @str => sprintf('SRCD: %s %s', splice @bytes, 0 => usize('S'))
Branch: 1 branch
BranchTrueFalseTotal
if @bytes 0 4 4
224 if @bytes;
225  
226 4 return @str;
227 4 };
228  
229 4 __PACKAGE__->meta->make_immutable();
« blib/lib/Net/EGTS/Record.pm ↑ Summary lib/Net/EGTS/Packet.pm »