BT368i.pm

filter: Statementstmt 50.0% 41 / 82 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 70.5% 12 / 17 Podpod 25.0% 1 / 4 totaltotal 47.7% 54 / 113 CC 7 SCAR 18.3
CC
7
Cov
45%
DESTROY
20.0
get_sentances
12.0
my_control_c
6.0
CRAP 6.3
« BT368i/NMEA/GP/GLL.pm ↑ Summary BT368i/NMEA/GP/GSV.pm »
1 #
2 # Written by Travis Kent Beste
3 # Fri Aug 6 14:26:05 CDT 2010
4  
5 package BT368i;
6  
7 1 ▶use strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use vars qw( );
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use RingBuffer;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 ▶use BT368i::Serial;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use BT368i::NMEA::GP::GSA;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use BT368i::NMEA::GP::GLL;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use BT368i::NMEA::GP::GGA;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use BT368i::NMEA::GP::GSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use BT368i::NMEA::GP::RMC;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use BT368i::NMEA::GP::VTG;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
20 1 ▶use IO::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 1 our @ISA = qw(RingBuffer BT368i::Serial BT368i::NMEA::GP::RMC BT368i::NMEA::GP::GSA BT368i::NMEA::GP::GGA BT368i::NMEA::GP::GSV BT368i::NMEA::GP::GLL BT368i::NMEA::GP::VTG);
23  
24 1 our $VERSION = sprintf("%d.%02d", q$Revision: 1.00 $ =~ /(\d+)\.(\d+)/);
25  
26 #----------------------------------------#
27 # capture control-c
28 #----------------------------------------#
29 1 my $control_c_counter = 0;
30 1 $SIG{INT} = \&my_control_c;
31 0 ▶sub my_control_c {
Subroutine my_control_c: not called CC=2 SCAR=17.9
Pod undocumented
32 0 $SIG{INT} = \&my_control_c;
33  
34 0 print "finishing up...";
35  
36 0 $control_c_counter++;
37 0 ▶ if ($control_c_counter == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($control_c_counter == 1) 0 0 0
38 0 print "done\n";
39 0 exit();
40 }
41 }
42  
43 #----------------------------------------#
44 #
45 #----------------------------------------#
46 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my $class = shift;
48 0 my %args = @_;
49  
50 my %fields = (
51 log_fh => '',
52 log_filename => '',
53  
54 serial => '',
55 serialport => $args{'Port'},
56 0 serialbaud => $args{'Baud'},
57 serialtimeout => 5, # 5 second timeout
58 serialline => '', # the line that we're parsing, so it doesn't get lost
59  
60 ringbuffer => '',
61 ringbuffersize => 4096,
62 verbose => 1,
63 );
64  
65 0 my $self = {
66 %fields
67 };
68 0 bless $self, $class;
69  
70 # initialize the ringbuffer
71 0 my $buffer = [];
72 0 my $ringsize = $self->{ringbuffersize};
73 0 my $overwrite = 0;
74 0 my $printextendedinfo = 0;
75 0 my $r = new RingBuffer(
76 Buffer => $buffer,
77 RingSize => $ringsize,
78 Overwrite => $overwrite,
79 PrintExtendedInfo => $printextendedinfo,
80 );
81 0 $r->ring_init();
82 0 $r->ring_clear();
83 0 $self->{ringbuffer} = $r;
84  
85 # connect to serial port
86 0 $self->connect();
87  
88 0 return $self;
89 }
90  
91 #----------------------------------------#
92 #
93 #----------------------------------------#
94 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=4 SCAR=30.0
95 0 my $self = shift;
96  
97 0 ▶ if ($self->{serial}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"serial"}) 0 0 0
98 0 ▶ $self->{serial}->close || die "failed to close serialport";
Branch: 1 branch
BranchTrueFalseTotal
$self->{"serial"}->close or die "failed to close serialport" 0 0 0
99 0 undef $self->{serial}; # frees memory back to perl
100 }
101  
102 0 ▶ $self->SUPER::DESTROY if $self->can("SUPER::DESTROY");
Branch: 1 branch
BranchTrueFalseTotal
if $self->can("SUPER::DESTROY") 0 0 0
103 }
104  
105 #----------------------------------------#
106 #
107 #----------------------------------------#
108 0 ▶sub log {
Subroutine log: not called CC=1 SCAR=6.9
Pod documented
109 0 my $self = shift;
110 0 my $filename = shift;
111  
112 # set the filename in the object
113 0 $self->{log_filename} = $filename;
114  
115 # create a new file handle object because the other objects use this and
116 # they end up sharing the same handle if we use a glob
117 0 my $fh = new IO::File->new;
118  
119 # generic open and unbuffered I/O
120 0 open($fh, ">" . $self->{log_filename});
121 0 select($fh), $| = 1; # set nonbuffered mode, gets the chars out NOW
122 0 $self->{log_fh} = (*$fh);
123 0 select(STDOUT);
124 }
125  
126 #----------------------------------------#
127 #
128 #----------------------------------------#
129 0 ▶sub get_sentances {
Subroutine get_sentances: not called CC=3 SCAR=24.8
Pod undocumented
130 0 my $self = shift;
131  
132 0 my $sentances = $self->BT368i::Serial::_readlines();
133  
134 # if we're logging, save data to filehandle
135 0 ▶ if ($self->{log_fh}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"log_fh"}) 0 0 0
136 0 foreach my $sentance (@$sentances) {
137 0 print { $self->{log_fh} } $sentance . "\n";
138 }
139 }
140  
141 0 return $sentances;
142 }
143  
144 1 1;
145  
146 __END__
« BT368i/NMEA/GP/GLL.pm ↑ Summary BT368i/NMEA/GP/GSV.pm »