gestione errori kill matlab dopo 12000 e MUSE

This commit is contained in:
2018-11-10 17:55:50 +01:00
parent 902146f379
commit 7c6c3f8de0
2 changed files with 335 additions and 393 deletions

View File

@@ -82,7 +82,7 @@ sub emailSend {
my $sender = new Mail::Sender { my $sender = new Mail::Sender {
auth => 'PLAIN', auth => 'PLAIN',
authid => 'ase.mums.alert@gmail.com', authid => 'ase.mums.alert@gmail.com',
authpwd => 'ASE@mums!', authpwd => 'ASE@mums2013F!',
smtp => 'smtp.gmail.com', smtp => 'smtp.gmail.com',
port => 587, port => 587,
from => 'ASE Alert System', from => 'ASE Alert System',

View File

@@ -24,10 +24,7 @@ my ( @CSVData, @sql );
my $outcount = 0; my $outcount = 0;
my $outfilenum = 0; my $outfilenum = 0;
my $maxsqllines = 10000; my $maxsqllines = 10000;
my ( my ($tool, $toolbatt, $tooltemp, $tooltype, @channels,@NewData, @din, @nodetype, $GDEventDate);
$tool, $toolbatt, $tooltemp, $tooltype, @channels,
@NewData, @din, @nodetype, $GDEventDate
);
my $matlab_ip = "160.78.21.71"; my $matlab_ip = "160.78.21.71";
my $matlab_cmd = "matlab.cmd"; my $matlab_cmd = "matlab.cmd";
my $matlab_timestamp = ""; my $matlab_timestamp = "";
@@ -38,16 +35,18 @@ my $ftp_passwd;
my $ftp_parm; my $ftp_parm;
my $ftp_filename; my $ftp_filename;
my $ftp_target; my $ftp_target;
my $duedate; my $duedate = '';
my ($unit_id, $unit, $unittype); my ($unit_id, $unit, $unittype);
my ($fileDate, $fileTime); my ($fileDate, $fileTime);
my $matlab_rt = "/usr/local/MATLAB/MATLAB_Runtime/v93"; my $matlab_rt = "/usr/local/MATLAB/MATLAB_Runtime/v93";
my $matlab_func_dir = "/usr/local/matlab_func/"; my $matlab_func_dir = "/usr/local/matlab_func/";
my $matlab_error = '';
my $matlab_timeout = '1200';
my $email_addr = 'andrea.carri@aseltd.eu,roberto.savi@aseltd.eu,alessandro.battilani@gmail.com'; my $email_addr = 'andrea.carri@aseltd.eu,roberto.savi@aseltd.eu,alessandro.battilani@gmail.com';
my ($email_msg, $email_obj); my ($email_msg, $email_obj);
sub getTimeStamp
{ # parm [ts] => timestamp for filename; log => timestamp for log sub getTimeStamp{ # parm [ts] => timestamp for filename; log => timestamp for log
my $format = "%04d%02d%02d%02d%02d%02d"; my $format = "%04d%02d%02d%02d%02d%02d";
my ($p1) = @_; my ($p1) = @_;
if ( defined $p1 and $p1 eq "log" ) { if ( defined $p1 and $p1 eq "log" ) {
@@ -56,42 +55,29 @@ sub getTimeStamp
if ( defined $p1 and $p1 eq "db_ts" ) { if ( defined $p1 and $p1 eq "db_ts" ) {
$format = "%04d-%02d-%02d %02d:%02d:%02d"; $format = "%04d-%02d-%02d %02d:%02d:%02d";
} }
my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) = my ( $sec, $min, $hour, $mday, $mon, $year, $wday, $yday, $isdst ) =localtime(time);
localtime(time); my $timestamp =sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec );
my $timestamp =
sprintf( $format, $year + 1900, $mon + 1, $mday, $hour, $min, $sec );
return $timestamp; return $timestamp;
} }
sub writeOutSql { sub writeOutSql {
my ($tn) = @_; my ($tn) = @_;
my $outfile = $sqlout . "_" . $outfilenum++; my $outfile = $sqlout . "_" . $outfilenum++;
open SQLOUT, ">", $outfile open SQLOUT, ">", $outfile
or die( getTimeStamp("log") or die( getTimeStamp("log"). " - pid $$ >> Error: opening output file ". $outfile. ":$!\n" );
. " - pid $$ >> Error: opening output file "
. $outfile
. ":$!\n" );
print getTimeStamp("log") . " - pid $$ >> file $outfile created\n"; print getTimeStamp("log") . " - pid $$ >> file $outfile created\n";
print SQLOUT "/* lock " print SQLOUT "/* lock ". $db_name. ".$table table */\nLOCK TABLES ". $db_name. ".$table WRITE;\n";
. $db_name
. ".$table table */\nLOCK TABLES "
. $db_name
. ".$table WRITE;\n";
print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n"; print SQLOUT "INSERT IGNORE INTO " . $db_name . ".$table\n";
print SQLOUT print SQLOUT "(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n";
"(`UnitName`,`ToolNameID`,`NodeNum`,`EventDate`,`EventTime`,`BatLevel`,`Temperature`,\n"; print SQLOUT "`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n";
print SQLOUT
"`Val0`,`Val1`,`Val2`,`Val3`,`Val4`,`Val5`,`Val6`,`Val7`,`Val8`,`Val9`,`ValA`,`ValB`,`ValC`,`ValD`,`ValE`,`ValF`)\n";
print SQLOUT "VALUES\n"; print SQLOUT "VALUES\n";
print SQLOUT @sql; print SQLOUT @sql;
@sql = (); @sql = ();
print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n"; print SQLOUT "/* unlock table */\nUNLOCK TABLES;\n";
close SQLOUT close SQLOUT
or die( getTimeStamp("log") or die( getTimeStamp("log"). " - pid $$ >> Error in closing file ". $outfile. "\n" );
. " - pid $$ >> Error in closing file "
. $outfile
. "\n" );
my @args = ( "mysql", "--login-path=asepath", "-e source " . $outfile ); my @args = ( "mysql", "--login-path=asepath", "-e source " . $outfile );
system(@args) == 0 system(@args) == 0
or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" ); or die( getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n" );
@@ -101,21 +87,30 @@ sub writeOutSql {
return; return;
} }
sub matlabCalc { sub matlabCalc {
getMatlabCmd(); getMatlabCmd();
$matlab_timestamp = getTimeStamp("db_ts"); $matlab_timestamp = getTimeStamp("db_ts");
print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc started...\n"; print getTimeStamp("log") . " - pid $$ >> $tool MatLab calc started...\n";
if ($matlab_cmd =~ /_lnx$/) { if ($matlab_cmd =~ /_lnx$/) {
$matlab_cmd = './run_' . $matlab_cmd . '.sh'; $matlab_cmd = './run_' . $matlab_cmd . '.sh';
#print $ENV{"HOME"} . "\n"; #print $ENV{"HOME"} . "\n";
$ENV{"HOME"} = "/" . $ENV{"HOME"}; $ENV{"HOME"} = "/" . $ENV{"HOME"};
chdir($matlab_func_dir) chdir($matlab_func_dir)
or die "cannot change: $!\n"; or die "cannot change: $!\n";
my @args = ( $matlab_cmd, $matlab_rt, $unit, $tool); my @args = ( 'timeout', $matlab_timeout, $matlab_cmd, $matlab_rt, $unit, $tool);
if (system(@args) != 0) { if (system(@args) != 0) {
my $exit_value = $? >> 8;
if ($exit_value == 124) {
print getTimeStamp("log") . " - pid $$ >> system @args excessive duration: killed after $matlab_timeout seconds\n";
$matlab_error = "Maltab elab excessive duration: killed after $matlab_timeout seconds";
} else {
print getTimeStamp("log") . " - pid $$ >> system @args failed: return code $exit_value - $?\n";
$matlab_error = "Maltab elab failed: $exit_value - $?";
}
makeEmailMsg(); makeEmailMsg();
emailSend(); emailSend();
print getTimeStamp("log") . " - pid $$ >> system @args failed: $?\n";
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; print getTimeStamp("log") . " - pid $$ >> Execution ended.\n";
exit(1); exit(1);
} }
@@ -123,24 +118,21 @@ sub matlabCalc {
$matlab_cmd = 'matlab_' . uc $matlab_cmd . '.cmd'; $matlab_cmd = 'matlab_' . uc $matlab_cmd . '.cmd';
my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`; my @out_matlab = `ssh1 $matlab_ip 'cmd /c $matlab_cmd ' $tool`;
if (index($out_matlab[-1], "Failure") != -1) { if (index($out_matlab[-1], "Failure") != -1) {
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> $tool MatLab calc failed.\n";
. " - pid $$ >> $tool MatLab calc failed.\n";
makeEmailMsg(); makeEmailMsg();
emailSend(); emailSend();
print getTimeStamp("log") . " - pid $$ >> Execution ended.\n"; print getTimeStamp("log") . " - pid $$ >> Execution ended.\n";
exit(1); exit(1);
} }
} }
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> $tool MatLab calc executed.\n";
. " - pid $$ >> $tool MatLab calc executed.\n";
return; return;
} }
sub trxelab { sub trxelab {
my $dbh = my $dbh =DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log"). " - pid $$ >> Could not connect to database: $DBI::errstr";
or die getTimeStamp("log")
. " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( my $sth = $dbh->prepare(
'select ftp_addrs, ftp_user, ftp_passwd, ftp_parm, ftp_filename, ftp_target, duedate from units 'select ftp_addrs, ftp_user, ftp_passwd, ftp_parm, ftp_filename, ftp_target, duedate from units
@@ -150,8 +142,7 @@ sub trxelab {
$sth->execute(); $sth->execute();
if ( $sth->rows < 0 ) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - pid $$ >> No unit ftp params selected.\n"; die getTimeStamp("log") . " - pid $$ >> No unit ftp params selected.\n";
} }else {
else {
while ( my $results = $sth->fetchrow_hashref ) { while ( my $results = $sth->fetchrow_hashref ) {
$ftp_addrs = $results->{'ftp_addrs'}; $ftp_addrs = $results->{'ftp_addrs'};
$ftp_user = $results->{'ftp_user'}; $ftp_user = $results->{'ftp_user'};
@@ -169,19 +160,11 @@ sub trxelab {
my $fileelab; my $fileelab;
if ( $ftp_filename eq "" ) { if ( $ftp_filename eq "" ) {
$fileelab = $fileelab ='/var/lib/mysql-files/'. $tool . '_'. getTimeStamp(). '.csv'; #mettere quello che si prende da query
'/var/lib/mysql-files/' }else {
. $tool . '_'
. getTimeStamp()
. '.csv'; #mettere quello che si prende da query
}
else {
$ftp_filename =~ s/(\$\w+)/$1/eeg; $ftp_filename =~ s/(\$\w+)/$1/eeg;
$ftp_filename =~ s/\s/_/g; $ftp_filename =~ s/\s/_/g;
$fileelab = $fileelab ='/var/lib/mysql-files/'. $ftp_filename . '_'. getTimeStamp() . '.csv';
'/var/lib/mysql-files/'
. $ftp_filename . '_'
. getTimeStamp() . '.csv';
} }
my $sthdo = $dbh->do( my $sthdo = $dbh->do(
@@ -206,68 +189,53 @@ sub trxelab {
$ftp_parm //= ""; $ftp_parm //= "";
$ftp_parm =~ s/\s//g; $ftp_parm =~ s/\s//g;
my %ftp_parms = ( my %ftp_parms = ('Host' => $ftp_addrs,);
'Host' => $ftp_addrs,
);
foreach my $parm (split(/,/, $ftp_parm)) foreach my $parm (split(/,/, $ftp_parm)){
{
my ($key, $val) = split(/=>/, $parm); my ($key, $val) = split(/=>/, $parm);
$ftp_parms{$key} = $val; $ftp_parms{$key} = $val;
} }
$ftp_parms{'Debug'} = 0;
$ftp_parms{'Passive'} = 1;
print getTimeStamp("log") . " - pid $$ >> $tool ftp parm:\n" . Dumper(%ftp_parms); print getTimeStamp("log") . " - pid $$ >> $tool ftp parm:\n" . Dumper(%ftp_parms);
if (($duedate eq '0000-00-00 00:00:00') or if ( !defined $duedate
($duedate eq '') or or($duedate eq '0000-00-00 00:00:00')
($duedate gt getTimeStamp("db_ts") )) { or($duedate eq '')
my $ftp = Net::FTP->new( %ftp_parms ) or($duedate gt getTimeStamp("db_ts") )) {
or die getTimeStamp("log") my $ftp = Net::FTP->new(%ftp_parms)
. " - pid $$ >> Cannot connect to $ftp_addrs: $@ \n"; or die getTimeStamp("log"). " - pid $$ >> Cannot connect to $ftp_addrs: $@ \n";
$ftp->login( $ftp_user, $ftp_passwd ) $ftp->login( $ftp_user, $ftp_passwd )
or die getTimeStamp("log") or die getTimeStamp("log"). " - pid $$ >> Cannot login ". $ftp->message . "\n";
. " - pid $$ >> Cannot login "
. $ftp->message . "\n";
$ftp_target //= ""; $ftp_target //= "";
if ( $ftp_target ne "" ) { if ( $ftp_target ne "" ) {
$ftp->cwd($ftp_target) $ftp->cwd($ftp_target)
or die getTimeStamp("log") or die getTimeStamp("log"). " - pid $$ >> Change remote dir failed ". $ftp->message . "\n";
. " - pid $$ >> Change remote dir failed "
. $ftp->message . "\n";
} }
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> ftp target: ". $ftp->pwd() . ".\n";
. " - pid $$ >> ftp target: "
. $ftp->pwd() . ".\n";
$ftp->put($fileelab) $ftp->put($fileelab)
or die getTimeStamp("log") or die getTimeStamp("log"). " - pid $$ >> Put failed: ". $ftp->message . "\n";
. " - pid $$ >> Put failed "
. $ftp->message . "\n";
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> ftp target lists ". scalar @{ $ftp->ls() }. " elements.\n";
. " - pid $$ >> ftp target lists "
. scalar @{ $ftp->ls() }
. " elements.\n";
$ftp->quit; $ftp->quit;
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> $tool: $fileelab ftp put executed.\n";
. " - pid $$ >> $tool: $fileelab ftp put executed.\n";
} else { } else {
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> $tool: $fileelab ftp put didn't executed because due date reached.\n";
. " - pid $$ >> $tool: $fileelab ftp put didn't executed because due date reached.\n";
} }
return; return;
} }
sub getNodesType { sub getNodesType {
my $dbh = my $dbh =DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log"). " - pid $$ >> Could not connect to database: $DBI::errstr";
or die getTimeStamp("log")
. " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( my $sth = $dbh->prepare(
'select t.name as name, n.seq as seq, n.num as num, n.channels as channels, y.type as type, n.din as din 'select t.name as name, n.seq as seq, n.num as num, n.channels as channels, y.type as type, n.din as din
from nodes as n from nodes as n
inner join tools as t on t.id = n.tool_id inner join tools as t on t.id = n.tool_id
inner join nodetypes as y on n.nodetype_id = y.id inner join nodetypes as y on n.nodetype_id = y.id
@@ -275,12 +243,10 @@ sub getNodesType {
) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; ) or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute(); $sth->execute();
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> $tool: " . $sth->rows . " rows selected to get node type/din/channels.\n";
. " - pid $$ >> $tool: " . $sth->rows . " rows selected to get node type/din/channels.\n";
if ( $sth->rows < 0 ) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - pid $$ >> No node channels selected.\n"; die getTimeStamp("log") . " - pid $$ >> No node channels selected.\n";
} }else {
else {
my $row = 0; my $row = 0;
while ( my $results = $sth->fetchrow_hashref ) { while ( my $results = $sth->fetchrow_hashref ) {
$channels[$row] = $results->{'channels'}; $channels[$row] = $results->{'channels'};
@@ -296,22 +262,17 @@ sub getNodesType {
return; return;
} }
sub getUdbPwd { sub getUdbPwd {
my $dbh = my $dbh =DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log"). " - pid $$ >> Could not connect to database: $DBI::errstr";
or die getTimeStamp("log") my $sth = $dbh->prepare("SELECT db_user, db_pwd FROM ase_lar.companies where db_name = '". $db_name. "';" )
. " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare(
"SELECT db_user, db_pwd FROM ase_lar.companies where db_name = '"
. $db_name
. "';" )
or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr"; or die getTimeStamp("log") . " - pid $$ >> $DBI::errstr";
$sth->execute(); $sth->execute();
if ( $sth->rows < 0 ) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") . " - pid $$ >> No password selected.\n"; die getTimeStamp("log") . " - pid $$ >> No password selected.\n";
} }else {
else {
my $results = $sth->fetchrow_hashref; my $results = $sth->fetchrow_hashref;
$password = $results->{'db_pwd'}; $password = $results->{'db_pwd'};
$username = $results->{'db_user'}; $username = $results->{'db_user'};
@@ -325,11 +286,10 @@ sub getUdbPwd {
return; return;
} }
sub getMatlabCmd { sub getMatlabCmd {
my $dbh = my $dbh =DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password )
DBI->connect( "DBI:mysql:$db_lar;host=$server", $username, $password ) or die getTimeStamp("log"). " - pid $$ >> Could not connect to database: $DBI::errstr";
or die getTimeStamp("log")
. " - pid $$ >> Could not connect to database: $DBI::errstr";
my $sth = $dbh->prepare( my $sth = $dbh->prepare(
'select m.matcall, t.ftp_send , t.unit_id from matfuncs as m 'select m.matcall, t.ftp_send , t.unit_id from matfuncs as m
@@ -339,10 +299,8 @@ sub getMatlabCmd {
$sth->execute(); $sth->execute();
if ( $sth->rows < 0 ) { if ( $sth->rows < 0 ) {
die getTimeStamp("log") die getTimeStamp("log"). " - pid $$ >> No tool's matlab function selected.\n";
. " - pid $$ >> No tool's matlab function selected.\n"; }else {
}
else {
while ( my $results = $sth->fetchrow_hashref ) { while ( my $results = $sth->fetchrow_hashref ) {
$matlab_cmd = $results->{'matcall'}; $matlab_cmd = $results->{'matcall'};
$ftp_send = $results->{'ftp_send'}; $ftp_send = $results->{'ftp_send'};
@@ -357,8 +315,9 @@ sub getMatlabCmd {
return; return;
} }
sub makeEmailMsg { sub makeEmailMsg {
$email_msg = <<"END_MSG"; $email_msg = <<"END_MSG";
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html> <html>
<head> <head>
@@ -382,7 +341,8 @@ $email_msg = <<"END_MSG";
<tr> <tr>
<td style="padding: 10px 10px 10px 10px;"> <td style="padding: 10px 10px 10px 10px;">
Alert from ASE: <BR> Alert from ASE: <BR>
Matlab function $matlab_cmd failed on unit => $unit - tool => $tool Matlab function $matlab_cmd failed on unit => $unit - tool => $tool <BR>
$matlab_error
</td> </td>
</tr> </tr>
</table> </table>
@@ -397,13 +357,14 @@ $email_msg = <<"END_MSG";
END_MSG END_MSG
} }
sub emailSend { sub emailSend {
$email_obj = 'Matlab error on unit ' . $unit . ' - tool ' . $tool; $email_obj = 'Matlab error on unit ' . $unit . ' - tool ' . $tool;
my $sender = new Mail::Sender { my $sender = new Mail::Sender {
auth => 'PLAIN', auth => 'PLAIN',
authid => 'ase.mums.alert@gmail.com', authid => 'ase.mums.alert@gmail.com',
authpwd => 'ASE@mums!', authpwd => 'ASE@mums2013F!',
smtp => 'smtp.gmail.com', smtp => 'smtp.gmail.com',
port => 587, port => 587,
from => 'ASE Alert System', from => 'ASE Alert System',
@@ -439,8 +400,7 @@ if ( $db_name ne 'asega' ) {
$db_sp = $db_name; $db_sp = $db_name;
getUdbPwd(); getUdbPwd();
$db_lar = $db_name; $db_lar = $db_name;
} }else {
else {
$db_name = 'ase_lar'; $db_name = 'ase_lar';
} }
@@ -451,9 +411,10 @@ if ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(DT\d\d\d\d|LOC\d.*|GD\d*)_\d*$/i ) {
($unittype, $unit ) = split( /\s/, uc <FILE> ); ($unittype, $unit ) = split( /\s/, uc <FILE> );
$unit =~ s/;+$//; $unit =~ s/;+$//;
} elsif ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)_\d*$/i ) { } elsif ( $filecsvname =~ m/^(\d\d_\d\d\d\d_|)(\d\d\d\d\d\d\d\d\d\d\d\d\d\d_)(G201_ID\d\d\d\d_DT\d\d\d\d)_\d*$/i ) {
# da mettere il controllo ^^^^^^^^^^^^^^^ se ha mese ed anno all'inivio # da mettere il controllo ^^^^^^^^^^^^^^^ se ha mese ed anno all'inivio
my @strings = $filecsvname =~ /(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})_(.{1,6})_(.{1,6}).*/; my @strings = $filecsvname =~ /(.{1,4})(.{1,2})(.{1,2})(.{1,2})(.{1,2})(.{1,2})_(.{1,4})_(.{1,6})_(.{1,6}).*/;
$fileDate = $strings[0] . "/" . $strings[1] . "/" . $strings[2];; $fileDate = $strings[0] . "/" . $strings[1] . "/" . $strings[2];
$fileTime = $strings[3] . ":" . $strings[4] . ":" . $strings[5]; $fileTime = $strings[3] . ":" . $strings[4] . ":" . $strings[5];
$unittype = $strings[6]; $unittype = $strings[6];
$unit = $strings[7]; $unit = $strings[7];
@@ -470,31 +431,25 @@ while ( my $line = <FILE> ) {
if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) { if ( defined $info[3] && $info[3] =~ m/^DT\d\d\d\d$/i ) {
$tool = uc $info[3]; $tool = uc $info[3];
$tooltype = uc $info[2]; $tooltype = uc $info[2];
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> Found $tooltype tool name: $tool\n";
. " - pid $$ >> Found $tooltype tool name: $tool\n";
getNodesType(); getNodesType();
} }elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) {
elsif ( defined $info[2] && $info[2] =~ m/^LOC\d*$/i ) {
$tool = uc $info[2]; $tool = uc $info[2];
$tooltype = 'LOC'; $tooltype = 'LOC';
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> Found $tooltype tool name: $tool\n";
. " - pid $$ >> Found $tooltype tool name: $tool\n";
getNodesType(); getNodesType();
} }elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) {
elsif ( defined $info[3] && $info[3] =~ m/^GD\d*$/i ) {
$tool = uc $info[3]; $tool = uc $info[3];
$tooltype = 'GD'; $tooltype = 'GD';
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> Found $tooltype tool name: $tool\n";
. " - pid $$ >> Found $tooltype tool name: $tool\n";
} }
} }else {
else {
$NodeData =~ s/\x0d{0,1}\x0a\Z//s; $NodeData =~ s/\x0d{0,1}\x0a\Z//s;
$NodeData =~ s/;+$//; $NodeData =~ s/;+$//;
#$NodeData =~ s/\r\n\z//; #$NodeData =~ s/\r\n\z//;
if ( $tooltype eq "MUX" ) { if ( $tooltype eq "MUX" or $tooltype eq "MUSE" ) {
#$NodeData =~ s/Dis\./N\/A/g; #$NodeData =~ s/Dis\./N\/A/g;
@NewData = grep /\S/, split( /\||;/, $NodeData ); @NewData = grep /\S/, split( /\||;/, $NodeData );
@@ -507,35 +462,25 @@ while ( my $line = <FILE> ) {
#print Dumper \@NewData; #print Dumper \@NewData;
#print Dumper \@din; #print Dumper \@din;
} }elsif ( $tooltype eq "LOC" ) {
elsif ( $tooltype eq "LOC" ) {
if ( !defined $din[0] ) { if ( !defined $din[0] ) {
print getTimeStamp("log") print getTimeStamp("log"). " - pid $$ >> Din not defined.\n";
. " - pid $$ >> Din not defined.\n"; print getTimeStamp("log"). " - pid $$ >> Execution ended.\n";
print getTimeStamp("log")
. " - pid $$ >> Execution ended.\n";
exit; exit;
} }
my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) = my ( $Vbat, $Tmod, $Ain1, $Ain2, $Din1, $Din2 ) =
split( /;/, $NodeData ); split( /;/, $NodeData );
$CSVData[0] = $Vbat . ";" . $Tmod; $CSVData[0] = $Vbat . ";" . $Tmod;
$CSVData[1] = $Din1; $CSVData[1] = $Din1;
} }elsif ( $tooltype eq "GD" ) {
elsif ( $tooltype eq "GD" ) {
my ( $div, $Vbat, $Tmod ) = my ( $div, $Vbat, $Tmod ) =
split( /;/, $NodeData ); split( /;/, $NodeData );
$CSVData[0] = $Vbat . ";" . $Tmod; $CSVData[0] = $Vbat . ";" . $Tmod;
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first ); my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
my ( $h, $min, $sec ) = split( /:/, $t ); my ( $h, $min, $sec ) = split( /:/, $t );
$GDEventDate = $y . '-' . $m . '-' . $d; $GDEventDate = $y . '-' . $m . '-' . $d;
$CSVData[1] = "DT" $CSVData[1] = "DT". substr( $tool, 2, 4 ) . ';'. $h . ':'. ( $min - 1 ) . ';'. $h . ':'. ( $min + 1 );
. substr( $tool, 2, 4 ) . ';' }else {
. $h . ':'
. ( $min - 1 ) . ';'
. $h . ':'
. ( $min + 1 );
}
else {
@CSVData = split( /\|/, $NodeData ); @CSVData = split( /\|/, $NodeData );
} }
@@ -546,8 +491,7 @@ while ( my $line = <FILE> ) {
if ( $nodenum eq 0 ) { if ( $nodenum eq 0 ) {
$toolbatt = $data[0]; $toolbatt = $data[0];
$tooltemp = $data[1]; $tooltemp = $data[1];
} }else {
else {
my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first ); my ( $y, $m, $d, $t ) = split( /[\s\/]/, $first );
if (length($y) != 4) { # G201 con la data invertita if (length($y) != 4) { # G201 con la data invertita
my $w = $y; my $w = $y;
@@ -566,8 +510,7 @@ while ( my $line = <FILE> ) {
if ( ++$outcount % $maxsqllines eq 0 ) { if ( ++$outcount % $maxsqllines eq 0 ) {
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n"; $sql[ ( $outcount % $maxsqllines ) - 1 ] .= ";\n";
writeOutSql($tool); writeOutSql($tool);
} }else {
else {
$sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n"; $sql[ ( $outcount % $maxsqllines ) - 1 ] .= ",\n";
} }
} }
@@ -581,8 +524,7 @@ $sql[ ( $outcount % $maxsqllines ) - 1 ] =~ s/,$/;/g;
writeOutSql($tool); writeOutSql($tool);
if ( $tooltype eq "GD" ) { if ( $tooltype eq "GD" ) {
print getTimeStamp("log") . " - pid $$ >> tool GD: nothing to do.\n"; print getTimeStamp("log") . " - pid $$ >> tool GD: nothing to do.\n";
} }else {
else {
matlabCalc(); matlabCalc();
if ($ftp_send) { if ($ftp_send) {
if ( $tool eq 'DT0076' ) { if ( $tool eq 'DT0076' ) {