#!/usr/bin/perl
#
# get list of DACS values from get_dac3 log table.
# and put into html table for inclusion into page...
#

# get commands to use
($source,$destination, $other) = @ARGV;
if($source eq "") {
  print "usage: dacs_tbl.pl source destination ( source is path and file name of log file)\n";
  exit(0);
}
if($destination eq "") {
  print "usage: dacs_tbl.pl source destination ( destination is path and file name of html file )\n";
  exit(0);
}

# get start time of run
$date = `date`;

@TMPLIST=(`tail -n 48 $source`);
# debug option
#print "@TMPLIST";

open ( FINDEX, ">$destination");
print FINDEX "<html><head><title>DACS Report</title></head>\n";
print FINDEX "<body><h2>DACS Report $date</h2>\n<p>\n";
print FINDEX "DACS report using Summary DATA \n<p>\n";
print FINDEX "<br>\n";
print FINDEX "<br> <b>DACS</b> = Data Acquisition And Control Board by BOBZ\n";
print FINDEX "<br> <b>NOTE:</b> data obtained by using the command s\n";
print FINDEX "<br> <b>NOTE:</b> not shown is command o~ which toggles outputs each reading\n";
print FINDEX "<br> <b>Volts In:</b> is battery voltage from Harbor Freight solar array.\n";
print FINDEX "<br><p>\n";
print FINDEX "<table border=0 cellpadding=4 cellspacing=4>\n";
print FINDEX "<tr><th>Date</th><th>Time</th>";
print FINDEX "<th>Inputs</th><th>Outputs</th><th>Volts In</th><th>Temperature</th></tr>\n";

foreach (sort @TMPLIST)
{
        chomp;
        ($tdate, $ttime, $tt1, $tt2, $tt3, $tt4, $tt5, $junk) = split(/\|/, $_);
        print FINDEX "<tr><td>$tdate</td><td>$ttime</td><td>$tt2</td>";
        print FINDEX "<td>$tt3</td><td>$tt4</td><td>$tt5</td>";
        print FINDEX "</tr>\n";

}

print FINDEX "</table>\n";
print FINDEX "<br>\n</p>\n";
print FINDEX "</body>\n</html>\n";
close FINDEX; 

exit(0);

