Commit b5a8ec81 authored by Jean-Luc Shaw's avatar Jean-Luc Shaw

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

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.
parent 12e7b467
...@@ -3,6 +3,9 @@ ...@@ -3,6 +3,9 @@
# DEPENDENCIES # DEPENDENCIES
use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm use GPS::NMEA ; # http://search.cpan.org/dist/perl-GPS/NMEA.pm
require "./sub_cruiseinfo.pl" ;
require "./sub_getgps.pl" ;
# HEADER AND INSTRUCTIONS # HEADER AND INSTRUCTIONS
print "========== ========== ========== LogGen ========== ========== ==========\n\n" ; print "========== ========== ========== LogGen ========== ========== ==========\n\n" ;
...@@ -17,60 +20,16 @@ print ">> Enter cruise directory : " ; ...@@ -17,60 +20,16 @@ print ">> Enter cruise directory : " ;
chop($folder = <STDIN>) ; chop($folder = <STDIN>) ;
print "\n" ; print "\n" ;
# does this cruise already have a mission log? # SETUP GPS
if (-e "$folder/LogGen/$name.out") { $gps = sub_getgps() ;
# Open the file handle to append
# Get the stations
# Get the operations
} else { # this cruise does not already have an output file
# MANAGE FILE HANDLES
# create and open the outfile handle
open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
print ">> Enter operations, end with CTRL-d : " ;
# operations to be conducted
$numops = 0 ;
while ( <STDIN> ) {
chop($_) ;
push(@ops,$_) ;
print ">> : " ;
$numops++ ;
}
print "\n" ;
# stations to be visited
$numsts = 0 ;
print ">> Enter stations names, end with CTRL-d : " ;
while (<STDIN>) {
chop($_) ;
push(@sts,$_) ;
print ">> : " ;
$numsts++ ;
}
print "\n\n\n" ;
# print header to outputfile
print OUT "\# $name\n" ;
print OUT "\# $folder\n" ;
print OUT "\# $numops\n" ;
for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }
print OUT "\# $numsts\n" ;
for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii]\n" ; }
print OUT "\# 0\n" ;
$cul = 0 ;
print OUT "\# Type lon lat yyyy mm dd HH MM SS Name\n" ;
$headerstring = "Starting operations log for $name cruise" ; # ASK FOR or READ CRUISE INFO
($ops,$sts,$numops,$numsts,$headerstring) = sub_cruiseinfo($name,$folder) ;
}
# SET PRINTING FORMAT # SET PRINTING FORMAT
$frmt = " \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ; $frmt = " \%4s \%.4f \%.4f \%4s \%2s \%2s \%2s \%2s \%2s \%s\n" ;
# DISPLAY AVAILABLE STATIONS and OPERATIONS # DISPLAY AVAILABLE STATIONS and OPERATIONS
print ">> AVAILABLE OPERATIONS ARE:\n"; print ">> AVAILABLE OPERATIONS ARE:\n";
foreach $line (@ops) { print ">> $line\n"; } foreach $line (@ops) { print ">> $line\n"; }
print ">> ---\n\n" ; print ">> ---\n\n" ;
...@@ -87,21 +46,21 @@ print "===== $headerstring =====\n" ; ...@@ -87,21 +46,21 @@ print "===== $headerstring =====\n" ;
print "=============================================================================================\n\n> " ; print "=============================================================================================\n\n> " ;
# RUNNING LOOP TO ADD TO CRUISE DATA FILE # RUNNING LOOP TO ADD TO CRUISE DATA FILE
while (<STDIN>) { while (<STDIN>) {
chop( $_ ) ;
@line = split( "=", $_ ) ;
# POLL COMPUTER FOR TIME # POLL COMPUTER FOR TIME
@time = localtime ; @time = localtime ;
$time[4]++ ; $time[5]+=1900 ; $time[4]++ ; $time[5]+=1900 ;
$mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4], @time[3], @time[2], @time[1] ; $mmddHHMM = sprintf "%02d/%02d %02d:%02d", @time[4], @time[3], @time[2], @time[1] ;
# POLL GPS FOR COORDINATES # POLL GPS FOR COORDINATES
($ns,$lat,$ew,$lon) = $gps->get_position ;
chop( $_ ) ;
@line = split( "=", $_ ) ;
# THIS IS THE EXIT COMMAND # THIS IS THE EXIT COMMAND
if ( $_ =~ /exit/) {last;} if ( $line[0] =~ /exit/) {last;}
# THIS IS A STATION ENTRY # THIS IS A STATION ENTRY
elsif ($line[0] =~ /st/) { elsif ($line[0] =~ /st/) {
...@@ -109,7 +68,9 @@ while (<STDIN>) { ...@@ -109,7 +68,9 @@ while (<STDIN>) {
if ( $cus =~ /none/ ) { # case : we are currently off station if ( $cus =~ /none/ ) { # case : we are currently off station
$cus = $line[1] ; $cus = $line[1] ;
$pre = ">>" ; $pre = ">>" ;
print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ; print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n" ;
print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ; printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
} elsif ($cus =~ /$line[1]/) { # case : we are currently at this station } elsif ($cus =~ /$line[1]/) { # case : we are currently at this station
...@@ -122,21 +83,25 @@ while (<STDIN>) { ...@@ -122,21 +83,25 @@ while (<STDIN>) {
printf OUT $frmt,$line[0],reverse @time[0..5],$cus ; printf OUT $frmt,$line[0],reverse @time[0..5],$cus ;
print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ; print "$pre\t\t\tEND OF STATION\t $cus,\t\t\t TIME : $mmddHHMM\n>\n>\n" ;
$cus = $line[1] ; $cus = $line[1] ;
print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n$pre " ; print "$pre\t\tNOW RECORDING STATION\t $line[1],\t\t\t TIME : $mmddHHMM\n" ;
print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ; printf OUT $frmt,$line[0],reverse @time[0..5],$line[1] ;
} }
} }
# THIS IS A NEW LEG ENTRY # THIS IS A NEW LEG ENTRY
elsif ($line[0] =~ /lg/) { elsif ($line[0] =~ /lg/) {
$cul++ ; $cul++ ;
print ">\tNOW RECORDING LEG $cul\n> " ; print ">\tNOW RECORDING LEG $cul\n> " ;
} }
# THIS IS AN OPERATION ENTRY # THIS IS AN OPERATION ENTRY
elsif ($line[0] =~ /op/) { elsif ($line[0] =~ /op/) {
foreach $op (@ops) { foreach $op (@ops) {
if ($line[1] =~ /$op/) { if ($line[1] =~ /$op/) {
print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n$pre " ; print "$pre\t\t\tOPERATION\t\t$line[1],\t\t\t\tTIME : $mmddHHMM\n" ;
print "$pre\t\t\t\t\t\t\t\t\t\tLON : $lon\n" ;
print "$pre\t\t\t\t\t\t\t\t\t\tLAT : $lat\n$pre " ;
} }
} }
} }
......
sub sub_cruiseinfo {
$name = $_[0] ;
$folder = $_[1] ;
# does this cruise already have a mission log?
if (-e "$folder/LogGen/$name.out") {
# Open the file handle to append
# Get the stations
# Get the operations
} else { # this cruise does not already have an output file
# MANAGE FILE HANDLES
# create and open the outfile handle
open(OUT,">$folder/LogGen/$name.out") || die("EXIT!! : Did not find LogGen folder or cruise folder\n") ;
print ">> Enter operations, end with CTRL-d : " ;
# operations to be conducted
$numops = 0 ;
while ( <STDIN> ) {
chop($_) ;
push(@ops,$_) ;
print ">> : " ;
$numops++ ;
}
print "\n" ;
# stations to be visited
$numsts = 0 ;
print ">> Enter stations names, end with CTRL-d : " ;
while (<STDIN>) {
chop($_) ;
push(@sts,$_) ;
print ">> : " ;
$numsts++ ;
}
print "\n\n\n" ;
# print header to outputfile
print OUT "\# $name\n" ;
print OUT "\# $folder\n" ;
print OUT "\# $numops\n" ;
for ($ii=0;$ii<$numops;$ii++) { print OUT "\# $ops[$ii]\n" ; }
print OUT "\# $numsts\n" ;
for ($ii=0;$ii<$numsts;$ii++) { print OUT "\# $sts[$ii]\n" ; }
print OUT "\# 0\n" ;
$cul = 0 ;
print OUT "\# Type lon lat yyyy mm dd HH MM SS Name\n" ;
$headerstring = "Starting operations log for $name cruise" ;
}
# RETURN NEEDED VALUES
return (\@ops,\@sts,$numops,$numsts,$headerstring) ;
}
1;
sub sub_getgps {
print ">> Use GPS...? [y/n] : " ;
chop($gpsans = <STDIN>) ;
print "\n" ;
if ($gpsans =~ /[yY]/) {
print ">> Port name...? : " ;
chop($gpsport = <STDIN>) ;
print "\n" ;
print ">> Baud rate...? : " ;
chop($gpsbaud = <STDIN>) ;
print "\n" ;
$gpson = 1 ;
} else {
$gpson = 0 ;
}
$gps = new GPS::NMEA( 'Port' => "$gpsport",
'Baud' => $gpsbaud,
);
return $gps ;
}
1;
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment