Commit b5a8ec812723198667b2130cf8a7cc053200a6d6

Authored by Jean-Luc Shaw
1 parent 12e7b467
Exists in master

This was a bit sloppy, I changed a lot things since the last commit. The script …

…talks to garmin gps units now but needs to be run as sudo. GPS settings and cruise info have been relocated to outboard subroutines. Still need to write the sign of longitude and latitude and to write them out to the data file.
Showing 3 changed files with 107 additions and 57 deletions   Show diff stats
@@ -3,6 +3,9 @@ @@ -3,6 +3,9 @@
3 # DEPENDENCIES 3 # DEPENDENCIES
4 use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm 4 use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm
5 5
  6 +require "./sub_cruiseinfo.pl" ;
  7 +require "./sub_getgps.pl" ;
  8 +
6 # HEADER AND INSTRUCTIONS 9 # HEADER AND INSTRUCTIONS
7 print "========== ========== ========== LogGen ========== ========== ==========\n\n" ; 10 print "========== ========== ========== LogGen ========== ========== ==========\n\n" ;
8 11
@@ -17,60 +20,16 @@ print ">> Enter cruise directory : " ; @@ -17,60 +20,16 @@ print ">> Enter cruise directory : " ;
17 chop($folder = <STDIN>) ; 20 chop($folder = <STDIN>) ;
18 print "\n" ; 21 print "\n" ;
19 22
20 -# does this cruise already have a mission log?  
21 -if (-e "$folder/LogGen/$name.out") {  
22 - # Open the file handle to append  
23 - # Get the stations  
24 - # Get the operations  
25 -  
26 -} else { # this cruise does not already have an output file  
27 -# MANAGE FILE HANDLES  
28 - # create and open the outfile handle  
29 - open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;  
30 - print ">> Enter operations, end with CTRL-d : " ;  
31 -  
32 - # operations to be conducted  
33 - $numops = 0 ;  
34 - while ( <STDIN> ) {  
35 - chop($_) ;  
36 - push(@ops,$_) ;  
37 - print ">> : " ;  
38 - $numops++ ;  
39 - }  
40 - print "\n" ;  
41 -  
42 -  
43 - # stations to be visited  
44 - $numsts = 0 ;  
45 - print ">> Enter stations names, end with CTRL-d : " ;  
46 - while (<STDIN>) {  
47 - chop($_) ;  
48 - push(@sts,$_) ;  
49 - print ">> : " ;  
50 - $numsts++ ;  
51 - }  
52 - print "\n\n\n" ;  
53 -  
54 - # print header to outputfile  
55 - print OUT "\# $name\n" ;  
56 - print OUT "\# $folder\n" ;  
57 - print OUT "\# $numops\n" ;  
58 - for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }  
59 - print OUT "\# $numsts\n" ;  
60 - for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii]\n" ; }  
61 - print OUT "\# 0\n" ;  
62 - $cul = 0 ;  
63 - print OUT "\# Type lon lat yyyy mm dd HH MM SS Name\n" ; 23 +# SETUP GPS
  24 +$gps = sub_getgps() ;
64 25
65 - $headerstring = "Starting operations log for $name cruise" ;  
66 -  
67 -} 26 +# ASK FOR or READ CRUISE INFO
  27 +($ops,$sts,$numops,$numsts,$headerstring) = sub_cruiseinfo($name,$folder) ;
68 28
69 # SET PRINTING FORMAT 29 # SET PRINTING FORMAT
70 $frmt = " \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ; 30 $frmt = " \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ;
71 31
72 # DISPLAY AVAILABLE STATIONS and OPERATIONS 32 # DISPLAY AVAILABLE STATIONS and OPERATIONS
73 -  
74 print ">> AVAILABLE OPERATIONS ARE:\n"; 33 print ">> AVAILABLE OPERATIONS ARE:\n";
75 foreach $line (@ops) { print ">> $line\n"; } 34 foreach $line (@ops) { print ">> $line\n"; }
76 print ">> ---\n\n" ; 35 print ">> ---\n\n" ;
@@ -87,21 +46,21 @@ print &quot;===== $headerstring =====\n&quot; ; @@ -87,21 +46,21 @@ print &quot;===== $headerstring =====\n&quot; ;
87 print "=============================================================================================\n\n> " ; 46 print "=============================================================================================\n\n> " ;
88 47
89 # RUNNING LOOP TO ADD TO CRUISE DATA FILE 48 # RUNNING LOOP TO ADD TO CRUISE DATA FILE
90 -  
91 while (<STDIN>) { 49 while (<STDIN>) {
92 50
  51 + chop( $_ ) ;
  52 + @line = split( "=", $_ ) ;
  53 +
93 # POLL COMPUTER FOR TIME 54 # POLL COMPUTER FOR TIME
94 @time = localtime ; 55 @time = localtime ;
95 $time[4]++ ; $time[5]+=1900 ; 56 $time[4]++ ; $time[5]+=1900 ;
96 $mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4], @time[3], @time[2], @time[1] ; 57 $mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4], @time[3], @time[2], @time[1] ;
97 58
98 # POLL GPS FOR COORDINATES 59 # POLL GPS FOR COORDINATES
99 -  
100 - chop( $_ ) ;  
101 - @line = split( "=", $_ ) ; 60 + ($ns,$lat,$ew,$lon) = $gps->get_position ;
102 61
103 # THIS IS THE EXIT COMMAND 62 # THIS IS THE EXIT COMMAND
104 - if ( $_ =~ /exit/) {last;} 63 + if ( $line[0] =~ /exit/) {last;}
105 64
106 # THIS IS A STATION ENTRY 65 # THIS IS A STATION ENTRY
107 elsif ($line[0] =~ /st/) { 66 elsif ($line[0] =~ /st/) {
@@ -109,7 +68,9 @@ while (&lt;STDIN&gt;) { @@ -109,7 +68,9 @@ while (&lt;STDIN&gt;) {
109 if ( $cus =~ /none/ ) { # case : we are currently off station 68 if ( $cus =~ /none/ ) { # case : we are currently off station
110 $cus = $line[1] ; 69 $cus = $line[1] ;
111 $pre = ">>" ; 70 $pre = ">>" ;
112 - print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ; 71 + print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n" ;
  72 + print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
  73 + print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
113 printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ; 74 printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
114 75
115 } elsif ($cus =~ /$line[1]/) { # case : we are currently at this station 76 } elsif ($cus =~ /$line[1]/) { # case : we are currently at this station
@@ -122,21 +83,25 @@ while (&lt;STDIN&gt;) { @@ -122,21 +83,25 @@ while (&lt;STDIN&gt;) {
122 printf OUT $frmt,$line[0],reverse @time[0..5],$cus ; 83 printf OUT $frmt,$line[0],reverse @time[0..5],$cus ;
123 print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ; 84 print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ;
124 $cus = $line[1] ; 85 $cus = $line[1] ;
125 - print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ; 86 + print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n" ;
  87 + print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
  88 + print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
126 printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ; 89 printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
127 } 90 }
128 } 91 }
129 # THIS IS A NEW LEG ENTRY 92 # THIS IS A NEW LEG ENTRY
130 elsif ($line[0] =~ /lg/) { 93 elsif ($line[0] =~ /lg/) {
131 $cul++ ; 94 $cul++ ;
132 - print ">\tNOW RECORDING LEG $cul\n> " ; 95 + print ">\tNOW RECORDING LEG $cul\n> " ;
133 } 96 }
134 97
135 # THIS IS AN OPERATION ENTRY 98 # THIS IS AN OPERATION ENTRY
136 elsif ($line[0] =~ /op/) { 99 elsif ($line[0] =~ /op/) {
137 foreach $op (@ops) { 100 foreach $op (@ops) {
138 if ($line[1] =~ /$op/) { 101 if ($line[1] =~ /$op/) {
139 - print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n$pre " ; 102 + print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n" ;
  103 + print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
  104 + print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
140 } 105 }
141 } 106 }
142 } 107 }
sub_cruiseinfo.pl 0 → 100644
@@ -0,0 +1,61 @@ @@ -0,0 +1,61 @@
  1 +sub sub_cruiseinfo {
  2 +
  3 + $name = $_[0] ;
  4 + $folder = $_[1] ;
  5 +
  6 + # does this cruise already have a mission log?
  7 + if (-e "$folder/LogGen/$name.out") {
  8 + # Open the file handle to append
  9 + # Get the stations
  10 + # Get the operations
  11 +
  12 + } else { # this cruise does not already have an output file
  13 + # MANAGE FILE HANDLES
  14 + # create and open the outfile handle
  15 + open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
  16 + print ">> Enter operations, end with CTRL-d : " ;
  17 +
  18 + # operations to be conducted
  19 + $numops = 0 ;
  20 + while ( <STDIN> ) {
  21 + chop($_) ;
  22 + push(@ops,$_) ;
  23 + print ">> : " ;
  24 + $numops++ ;
  25 + }
  26 + print "\n" ;
  27 +
  28 +
  29 + # stations to be visited
  30 + $numsts = 0 ;
  31 + print ">> Enter stations names, end with CTRL-d : " ;
  32 + while (<STDIN>) {
  33 + chop($_) ;
  34 + push(@sts,$_) ;
  35 + print ">> : " ;
  36 + $numsts++ ;
  37 + }
  38 + print "\n\n\n" ;
  39 +
  40 + # print header to outputfile
  41 + print OUT "\# $name\n" ;
  42 + print OUT "\# $folder\n" ;
  43 + print OUT "\# $numops\n" ;
  44 + for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }
  45 + print OUT "\# $numsts\n" ;
  46 + for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii]\n" ; }
  47 + print OUT "\# 0\n" ;
  48 + $cul = 0 ;
  49 + print OUT "\# Type lon lat yyyy mm dd HH MM SS Name\n" ;
  50 +
  51 + $headerstring = "Starting operations log for $name cruise" ;
  52 +
  53 + }
  54 +
  55 + # RETURN NEEDED VALUES
  56 + return (\@ops,\@sts,$numops,$numsts,$headerstring) ;
  57 +
  58 +
  59 +}
  60 +
  61 +1;
sub_getgps.pl 0 → 100644
@@ -0,0 +1,24 @@ @@ -0,0 +1,24 @@
  1 +sub sub_getgps {
  2 + print ">> Use GPS...? [y/n] : " ;
  3 + chop($gpsans = <STDIN>) ;
  4 + print "\n" ;
  5 + if ($gpsans =~ /[yY]/) {
  6 + print ">> Port name...? : " ;
  7 + chop($gpsport = <STDIN>) ;
  8 + print "\n" ;
  9 + print ">> Baud rate...? : " ;
  10 + chop($gpsbaud = <STDIN>) ;
  11 + print "\n" ;
  12 + $gpson = 1 ;
  13 + } else {
  14 + $gpson = 0 ;
  15 + }
  16 + $gps = new GPS::NMEA( 'Port' => "$gpsport",
  17 + 'Baud' => $gpsbaud,
  18 + );
  19 +
  20 +
  21 + return $gps ;
  22 +}
  23 +
  24 +1;