use strict; use warnings; use constant SCRIPT_NAME => "ErrorTracking.pl"; use constant SCRIPT_VERSION => "1.0.0"; use Data::Dumper; use Log4test; #use XML::Parser; #use HTML::Parser; #-----Variables--------------------------------------------------------------------------------------- # INCA NAME = Inca Signalname # INCA SIGNAL VALUE CHECK = Inca Signalname Check Value # INCA SIGNAL COMMENT = Comment for Inca Signalname check # INTERNAL NAME = ECU Internal Variable # INTERNAL VALUE CHECK = Internal Variable Check Value # INTERNAL COMMENT = Comment for Internal Variable check # RESOLUTION VALUE CHECK = Internal/Bus Resolution Check Value # RESOLUTION COMMENT = Internal/Bus Resolution Comment # SIGNAL CONVERSION CHECK = Signal Conversion Check Value # SIG. CONVERSION COMMENT = Signal Conversion Comment # BUS VALUE = on the Bus sent Value # ECU VALUE = from CCP collected ECU Value # DEVIATION = Signal deviation Log_SetOutDir("."); Log_SetOutFile("log_ErrorTracking.log"); # HTML file, INI file and output directory are given as command line argument my $DIR = $ARGV[0]; my $out_dir = $ARGV[1]; opendir (DIR, $DIR) || die ('Erreur Open $DIR'); my @files = readdir(DIR); my $html_hash_file = $out_dir . "\\html_hash" . ".txt"; Log_Info("Running script " . SCRIPT_NAME . " version " . SCRIPT_VERSION); Log_Info("USAGE: " . SCRIPT_NAME . " []"); # check for valid input parameter if(! defined $DIR or ! -f $DIR) { Log_Error("No directory given!"); die; } if(defined $out_dir) { if(! -d $out_dir) { mkdir $out_dir; } } else { $out_dir = "."; } # ------------------------------------------------------------------------------------------------- # BEGIN - MAIN # ------------------------------------------------------------------------------------------------- foreach (@files) { my $html_file = $_; #print " $html_file\n"; Log_Info("Script parameters"); Log_Info("HTML file: '$html_file'"); Log_Info("Output directory: '$out_dir'"); Log_Info("Data HTML hash: '$html_hash_file'\n"); my $data_ref; # reference to the data from the html database $data_ref = ReadDatabase($html_file); DumpHash($data_ref, $html_hash_file); } # ------------------------------------------------------------------------------------------------- # END - MAIN # ------------------------------------------------------------------------------------------------- sub ReadDatabase { my $Inca_Name; my ($in_file) = @_; my @data; if(! open(readFile, $in_file)) { Log_Error("Cannot read html file: '$in_file'"); die; } my $info_ref; while (my $line = ) { if ($line =~ /href\=/) { } # ------------------------------------------------------------------------------------------------- # INCA Variable check bloc # ------------------------------------------------------------------------------------------------- if ($line =~ /class\=/ and $line =~ /CAN signal/) { my @INCAVar; my %Sig_Incadata; #my $Inca_Name; my $Inca_Vchk; my $Inca_Comment; #-------------------------collect Signal Informations-------------------------------------------------- ($Inca_Vchk, $Inca_Name, $Inca_Comment)= $line =~ /^<[A-Z]+\s+[a-z]+\=\'([a-z]+)\'><[A-Z]+>[^0-9]+<\/[A-Z]+><[A-Z]+>\'([a_zA-Z0-9_]+)\'\s+([^0-9]*?)<[^0-9]+/; Log_Debug("-----------------INCA VARIABLE-----------"); Log_Debug("INCA NAME: $Inca_Name"); Log_Debug("INCA Variable Check: $Inca_Vchk"); Log_Debug("INCA Variable Comment: $Inca_Comment\n"); $Sig_Incadata{'INCA NAME'} = $Inca_Name; $Sig_Incadata{'INCA SIGNAL VALUE CHECK'} = $Inca_Vchk; $Sig_Incadata{'INCA SIGNAL COMMENT'} = $Inca_Comment; $Sig_Incadata{'INCA VARIABLE'} = \@INCAVar; $info_ref = \%Sig_Incadata; # add Inca Signal Infos to data array push(@data, $info_ref); } # ------------------------------------------------------------------------------------------------- # END INCA Variable check bloc # ------------------------------------------------------------------------------------------------- # ------------------------------------------------------------------------------------------------- # Internal Variable check bloc # ------------------------------------------------------------------------------------------------- if ($line =~ /class\=/ and $line =~ /ECU internal variable/) { my @IntVar; my %Sig_Intdata; my $Int_Vchk; my $Int_Name; my $Int_Comment; #----------------------------------collect Signal Informations------------------------------------------- my $regexp = qr { class='([^']+)'.*?'([^']+)'\s*([^<]+) }x; # ENDE Regexp ($Int_Vchk, $Int_Name, $Int_Comment) = $line =~ $regexp; Log_Debug("-------------INTERNAL VARIABLE-----------"); Log_Debug("INTERNAL NAME: $Int_Name"); Log_Debug("INTERNAL Variable Check: $Int_Vchk"); Log_Debug("INTERNAL Variable Comment: $Int_Comment\n"); $Sig_Intdata{'INTERNAL NAME'} = $Int_Name; $Sig_Intdata{'INTERNAL VALUE CHECK'} = $Int_Vchk; $Sig_Intdata{'INTERNAL COMMENT'} = $Int_Comment; $Sig_Intdata{'INTERNAL VARIABLE'} = \@IntVar; $info_ref = \%Sig_Intdata; push(@data, $info_ref); } # ------------------------------------------------------------------------------------------------- # END Internal Variable check bloc # ------------------------------------------------------------------------------------------------- # ------------------------------------------------------------------------------------------------- # Bus resolution check bloc # ------------------------------------------------------------------------------------------------- if ($line =~ /class\=/ and $line =~ /ECU internal resolution/) { my %resolution; my @BusResol; my $Res_Vchk; my $Res_Com; #---------------------------------collect Signal Informations----------------------------------------- my $regexp = qr { class='([^']+)'.*?(.*) }x; # ENDE Regexp ($Res_Vchk, $Res_Com) = $line =~ $regexp; Log_Debug("-------------BUS RESOLUTION---------------"); Log_Debug("Resolution check: $Res_Vchk"); Log_Debug("Resolution Comment: $Res_Com\n"); Log_Debug("-------------SIGNAL CONVERSION-----------"); $resolution{'RESOLUTION VALUE CHECK'} = $Res_Vchk; $resolution{'RESOLUTION COMMENT'} = $Res_Com; $resolution{'BUS RESOLUTION'} = \@BusResol; $info_ref = \%resolution; push(@data, $info_ref); } # ------------------------------------------------------------------------------------------------- # END Bus resolution check bloc # ------------------------------------------------------------------------------------------------- # ------------------------------------------------------------------------------------------------- # Signal conversion check bloc # ------------------------------------------------------------------------------------------------- if ($line =~ /class='/ and ($line !~ /ECU internal resolution/)and ($line =~ /$Inca_Name/) and ($line =~ /\d+/)) { my %SignalConv; my @SigConv; my $Sig_ConChk; my $Sig_ConCom; my $Bus_Value; my $Ecu_Value; my $deviation; #------------------------------collect Signal Informations--------------------------------------------- my $regexp = qr { class='([^']+)'[^0-9]+([^,]+)<\/TD>[^0-9]+([^,]+)<\/TD>([^,]+)<\/TD>([^']+) }x; # ENDE Regexp ($Sig_ConChk, $Bus_Value, $Ecu_Value, $deviation, $Sig_ConCom)= $line =~ $regexp; Log_Debug("Signal Conversion Check: $Sig_ConChk"); Log_Debug("BUS Value: $Bus_Value"); Log_Debug("ECU Value: $Ecu_Value"); Log_Debug("DEVIATION: $deviation"); Log_Debug("Signal Conversion Comment: $Sig_ConChk\n"); $SignalConv{'SIGNAL CONVERSION CHECK'} = $Sig_ConChk; $SignalConv{'BUS VALUE'} = $Bus_Value; $SignalConv{'ECU VALUE'} = $Ecu_Value; $SignalConv{'DEVIATION'} = $deviation; $SignalConv{'SIG. CONVERSION COMMENT'} = $Sig_ConCom; $SignalConv{'SIGNAL CONVERSION'} = \@SigConv; $info_ref = \%SignalConv; push(@data, $info_ref); } # ------------------------------------------------------------------------------------------------- # END Signal conversion check bloc # ------------------------------------------------------------------------------------------------- } return \@data; } sub DumpHash { my ($hash_ref, $file) = @_; local $Data::Dumper::Purity = 1; open (write_handle, ">$file") or die "\nERROR cannot write file: '$file'\n"; print write_handle Dumper($hash_ref); close (write_handle); } <>;