head	1.4;
access;
symbols;
locks
	root:1.4; strict;
comment	@# @;


1.4
date	2024.10.03.14.03.41;	author root;	state Exp;
branches;
next	1.3;

1.3
date	2024.09.17.17.50.59;	author root;	state Exp;
branches;
next	1.2;

1.2
date	2024.09.17.17.50.33;	author root;	state Exp;
branches;
next	1.1;

1.1
date	2024.09.16.18.23.32;	author root;	state Exp;
branches;
next	;


desc
@works.
-bert
@


1.4
log
@as I found it. seeing problem w/misalignment of keys. next version might fix it.
-bert
@
text
@#!/usr/bin/perl

use lib qw (/var/www/www.rcflightpath.com/lib);
use POSIX qw(strftime);
use CGI qw(:standard :html3 :all *table *Tr *td unescape);
use CGI::Cookie;

use Templates::Navbar;
use Templates::Header;
use Templates::Footer;

my $mode = param('mode');
my $show_all = param('show_all');
my $diff_only = param('diff_only');
my $pids_only = param('pids_only');
my $step = param('step');
my $filepath = '/var/www/www.rcflightpath.com/templates/rcfp.cgi';
my $title = 'Rotorflight Dump Config Comparison';

if (-e 'style.css') {
  $style = 'style.css';
} elsif (-e '../style.css') {
  $style = '../style.css';
} elsif (-e '../../style.css') {
  $style = '../../style.css';
} else {
  $style = '/style.css';
}

if (($mode eq 'save')&&($ratio)&&($observation)) {
  my $new_cookie = CGI::Cookie->new(
      -name => $ratio,
      -value => $observation,
      -expires => '+1y'
  );
  print $cgi->header(-cookie => [$new_cookie]);
} elsif (($mode eq 'clear')&&($ratio)) {
  my $new_cookie = CGI::Cookie->new(
      -name => $ratio,
      -value => '',
      -expires => '-1d'
  );
  print $cgi->header(-cookie => [$new_cookie]);
} else {
  print header;
}

print  start_html(
         -title=> $title,
         -style=> {'src' => $style},
         -meta=>  {'viewport'=>'width=device-width, initial-scale=1.0','description'=>$page_desc,'keywords'=>$keywords}
       ),"\n";

print start_table({-border=>0,-margin=>0,-topmargin=>0,-cellpadding=>0,-cellspacing=>0,-width=>900}),"<!-- START MAIN TABLE -->\n",
       start_Tr,"<!-- START HEADER -->\n",
        start_td({-colspan=>2}),"\n";
         Header::print_titlebar($title,$filepath,'FFFFFF');
print   end_td,"\n",
       end_Tr,"<!-- END HEADER -->\n",
       start_Tr,"<!-- START NAVBAR -->\n",
        start_td({-width=>150,-rowspan=>3}),"\n";
         Navbar::default2('sections','tuning_ikon','tuning_gen');
print   end_td,"<!-- END NAVBAR -->\n",
        start_td({-valign=>'top'}),div({-id=>'main'}),"<!-- START CONTENT -->\n";
         &print_content;
print   end_td,"\n",
       end_Tr,"<!-- END CONTENT -->\n",
       start_Tr,"<!-- START FOOTER -->\n",
        start_td({-align=>'center'}),"\n";
         Footer::print_footer;
print   end_td,"\n",
       end_Tr,"<!-- END FOOTER -->\n",
      end_table,"<!-- END MAIN TABLE -->\n",
     end_html;

sub print_content {
  if ($mode eq 'submit') {

    $file1 = param('dump1');
    $file2 = param('dump2');

    if (($file1 !~ /(\.(txt|dmp))$/)||($file2 !~ /(\.(txt|dmp))$/)) {
      print font({-color=>'red'},'Error: You accidentally selected an invalid file. Please hit your "Back" button and try again');
    } elsif ($file1 eq $file2) {
      print font({-color=>'red'},'Error: You need to choose two <b>different</b> files to activate this program. You accidentally chose the same file. Please hit your "Back" button and try again');
    } elsif (($file1)&&($file2)) {
        $upload_dir = '/var/www/www.rcflightpath.com/heli/configs/RotorFlight/tmp';
        $query = new CGI;
        $upload_filehandle = $query->upload("dump1");
    
        open UPLOADFILE, ">$upload_dir/$file1";
        while ( <$upload_filehandle> ) {
          print UPLOADFILE;
        }
        close UPLOADFILE;
    
        $upload_filehandle = $query->upload("dump2");
        open UPLOADFILE, ">$upload_dir/$file2";
        while ( <$upload_filehandle> ) {
          print UPLOADFILE;
        }
        close UPLOADFILE;
    
      chdir $upload_dir;
      if ($diff_only) {
        print font({-color=>'red',-size=>'+1'},'<B>NOTE:</B> Below is a listing of <U>ONLY THE DIFFERENCES</U> between your two files.<BR><DD>&nbsp;&nbsp;&nbsp;   To get other comprehensive views hit the "Back" button and select the other views.</DD>'),p;
        chomp (@@difference = `/usr/bin/diff $file1 $file2`);
        foreach $line(@@difference) {
          $line =~ s/\s+set\s+//;
          if ($line =~ s/^\<//) {
            ($key,$val) = split/\=/,$line;
            $db1{$key}=$val;
          }
          if ($line =~ s/^\>//) {
            ($key,$val) = split/\=/,$line;
            $db2{$key}=$val;
          }
        } 
        foreach (sort keys %db1) {
          $master{$_} = 1;
        }
        foreach (sort keys %db2) {
          $master{$_} = 1;
        }
        print start_table({-border=>1});
        print Tr(th('Parameter'),th($file1),th($file2));
        foreach (sort keys %master) {
          print Tr(td(b($_)),td({-align=>'center'},$db1{$_}),td({-align=>'center'},$db2{$_}));
        }
        print end_table;
      } elsif ($show_all) {
        print font({-color=>'red',-size=>'+1'},'<B>NOTE:</B> Scroll down and search for cells in <B>RED</B> to see the highlighted differences between your two files'),p;
        chomp (@@file1 = `/bin/cat $file1`);
        chomp (@@file2 = `/bin/cat $file2`);
        print start_table({-border=>1});
        print Tr(th('&nbsp;'),th($file1),th($file2));
        foreach $file1(@@file1) {
          $file2 = shift(@@file2);
          if ($file1 ne $file2) {
            print Tr(td({-bgcolor=>'red'},font({-color=>'#FFFFFF'},'Difference'),td(font({-color=>'red'},($file1))),td(font({-color=>'red'},$file2))));
          } else {
            print Tr(td('&nbsp;'),td($file1),td($file2));
          }
        }
        print end_table;
      } elsif ($pids_only) {
        print font({-color=>'red',-size=>'+1'},'<B>NOTE:</B> Scroll down and search for cells in <B>RED</B> to see the highlighted differences between your two files'),p;
        chomp (@@file1 = `/bin/cat $file1`);
        chomp (@@file2 = `/bin/cat $file2`);

        undef $flag;
        foreach $line(@@file1) {
          $flag = 1 if ($line =~ /^\#\s+(rate)?profile\s+\d+/);
          $flag = 0 if ($line =~ /^\#\s+restore\s+original\s+/);
#         next if ($line =~ /^(rate)?profile/);
          push(@@file1a,$line) if ($flag);
        }
        undef $flag;
        foreach $line(@@file2) {
          $flag = 1 if ($line =~ /^\#\s+(rate)?profile\s+\d+/);
          $flag = 0 if ($line =~ /^\#\s+restore\s+original\s+/);
#         next if ($line =~ /^(rate)?profile/);
          push(@@file2a,$line) if ($flag);
        }

        print start_table({-border=>1});
        print Tr(th('&nbsp;'),th($file1),th($file2));
        foreach $file1(@@file1a) {
          $file2 = shift(@@file2a);
          if ($file1 ne $file2) {
            print Tr(td({-bgcolor=>'red'},font({-color=>'#FFFFFF'},'Difference'),td(font({-color=>'red'},($file1))),td(font({-color=>'red'},$file2))));
          } elsif ($file1 =~ s/^\#\s+//) {
            $file1 =~ s/(\d+)//;
            $pnum = $1;
            $pnum++;
            print Tr(th({-colspan=>3},"$file1 $pnum"));
            undef $pnum;
          } else {
            print Tr(td('&nbsp;'),td($file1),td($file2));
          }
        }
        print end_table;
      }
    } else {
      print font({-color=>'red'},'Error: You need to choose two files to activate this program. Please hit your "Back" button and try again');
    }


  } else {
    print h2('RotorFlight Config Difference Checking Tool'),font({-color=>'red',-size=>'+1'},'<B>Purpose:</B> To provide a fast way to compare <U><I>TWO DIFFERENT</I></U> Rotorflight dump configurations'),p,
          strong('Instructions:'),br,
          'Use the below form to select two different RotorFlight configurations (TXT files) from your computer. Upon hitting "Upload Files", you will be presented with a table of all the configurations of each file and if this program finds any differences in values between the two config files, it will highlight them in RED.',p,
          'Use this tool for quickly finding a difference between 2 RotorFlight config files:',
          li('Between two different models for understanding or debug behavior purposes'),
          li('Between a configuration of the same model saved at an earlier time'),p,
          hr,
          start_form({-action=>'index.cgi',-method=>'post',-enctype=>'multipart/form-data'}),
          'RotorFlight Config File no. 1 (Dump file): ',input({-type=>'file',-name=>'dump1'}),br,
          'RotorFlight Config File no. 2 (Dump file): ',input({-type=>'file',-name=>'dump2'}),br,br,
          hidden({-value=>'submit',-name=>'mode'}),
          font({-color=>'red',-size=>'+1'},'Select which view type: '),
          input({-type=>'submit',-name=>'show_all',-value=>'Show All'}),
          input({-type=>'submit',-name=>'diff_only',-value=>'Show Diff Only'}),
          input({-type=>'submit',-name=>'pids_only',-value=>'Show PIDs Only'}),
          end_form;
  }
}
@


1.3
log
@this is the one that works before I changed style.
-bert
@
text
@d3 1
d5 6
a10 1
use CGI qw(:standard :html3 :all *table *Tr *td);
a11 1
$user_agent = user_agent();
d17 2
a18 10
$logo_font2 = 'FFB400';
$page_desc = 'RotorFlight configuration checker';
$auc = $ftc = $bsc = '5D5C61';
$debug = 1;
$basedir = '/var/www/www.rcflightpath.com/heli/configs';
$cgipath = "$basedir/index.cgi";

charset('UTF-8');

print header;
d21 5
a25 1
  $style = "$basedir/style.css";
a26 1
  #$style = '/var/www/www.rcflightpath.com/style.css';
d30 18
d49 26
a74 77
          -title => "$title",
          -style => {'src' => $style},
          -meta=> {'viewport'=>'width=device-width, initial-scale=1.0','description'=>$page_desc}
        );

print "<!-- Google tag (gtag.js) -->
      <script async src='https://www.googletagmanager.com/gtag/js?id=G-3D6XXHE4VQ'></script>
      <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'G-3D6XXHE4VQ');
      </script>";

# TOP TITLE AREA

  my $mod_time = (stat($cgipath))[9];
  my ($sec, $min, $hour, $mday, $mon, $year) = localtime($mod_time);

  @@months = qw /null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
  $mon++;  # Adjust month (0-based index)
  $year += 1900;  # Adjust year (start from 1900)
  $ampm = 'a.m.';
  $ampm = 'p.m.' if ($hour > 11);
  $hour = "0$hour" if ($hour < 11);
  $min  = "0$min"if ($min < 11);

  print start_table({-border=>0,-cellpadding=>0,-cellspacing=>0,-topmargin=>0,-width=>800}), # MAIN TABLE
          start_Tr,
            start_td({-colspan=>2,-bgcolor=>'#5D5C61'}),
              div({-id=>'title'},
                center(
                  table({-border=>0,-width=>'100%',-background=>'/images/bg.png'}, # TITLE TABLE
                    Tr(
                      td({-align=>'center',-width=>300},
                        img({-border=>0,-height=>143,-width=>300,src=>'/images/logo6.png'})),
                      td({-align=>'center'},
                        h1("<b><font color=white>RC</font> <font color=$logo_font2>FlightPath</font></b>"),
                        h2($title),
                        font({-color=>'white'},"Last updated: $months[$mon] $mday, $year @@ $hour:$min $ampm"),
                      ),
                    )
                  )
                ),
              ),
            end_td, 
          end_Tr;

# LEFT SIDE NAVIGATION

  print   start_Tr,
            start_td({-valign=>'top',-bgcolor=>'#B1A296'}), # NAVBAR HERE
              "<div id='navigation'>\n",
              "<ul>",
              "    <li><a href='/articles/pid-tuning/rotorflight'><font color=$auc><b>RotorFlight Blackbox Tuning</b></font></a></li>",p,"\n",
              "  </ul>","\n",
              "</div>\n\n";
            end_td,




# MAIN PAGE SECTION

  print start_td({-bgcolor=>'#EEE2DC',-valign=>'top'}),
        "<div id='main'>\n";

  &print_content;

  print "</div>\n",
        end_td,"\n",
        end_Tr,"\n",
        end_table,"\n";

  &print_footer;

  print end_html;
d106 1
d132 1
d147 1
d190 1
a190 1
    print h3('RotorFlight Config Difference Checking Tool'),p,
d201 1
a206 22
}

sub print_footer {

  print br,br,'<footer>',
    start_table({-border=>0}),
      start_Tr,
        start_td,
          font({-size=>'-1'},"DBUG: mode=$mode step=$step show_all=$show_all diff_only=$diff_only,pids_only=$pids_only"),
        end_td,
      end_Tr,
      start_Tr,
        '&nbsp;',
      end_Tr,
      start_Tr,
        start_td({-align=>'center'}),
          font({-size=>'-1'},'&copy; 2024 RC FlightPath RC Flight Training & Build Services | San Fernando Valley, CA'),
        end_td,
      end_Tr,
    end_table,
  '</footer>';

@


1.2
log
@this is an old one. checking it in for keepsake
-bert
l
@
text
@d8 7
a14 4
my $file = param('incoming_file');
my $newfilename = param('newfilename');
my $dump = param('dump');
my $comments = param('comments');
d16 4
a19 5
$dir_full = '/var/www/www.rcflightpath.com/articles/pid-tuning/rotorflight/field_reports/images';
$reports = '/var/www/www.rcflightpath.com/articles/pid-tuning/rotorflight/field_reports';
$dir_http = '/articles/pid-tuning/rotorflight/field_reports';
$newfilename = $file;
$newfilename =~ s/(jpg|jpeg|png|gif)/html/;
d23 2
a24 30

if ($mode eq 'submit') {

  open (NEW,">$reports/$newfilename");

  print NEW start_table({-border=>5,-cellpadding=>3}),"\n";

  print NEW start_Tr,"\n";
  print NEW start_td({-colspan=>2}),"\n";
  &print_report_header;
  print NEW end_td,"\n";
  print NEW end_Tr,"\n";

  print NEW start_Tr,"\n";
  print NEW start_td({-valign=>'top'}),"\n";
  &print_pid_table;
  print NEW hr,br,"\n";
  &print_comments;

  print NEW end_td,"\n";
  print NEW start_td,"\n";

  &print_bblog;

  print NEW end_td,"\n";
  print NEW end_Tr,"\n";
  print NEW end_table,"\n";
  close NEW;

  print br,br,'Your new report is here: ', a({-href=>"$dir_http/$newfilename"},$newfilename);
d26 2
a27 1
  &print_input_form;
d30 187
a216 19
sub print_input_form {
  print h3('Blackbox PID Trace Report'),hr,
        'profile 0',br,
        'dump profile',br,br,
        'profile 1',br,
        'dump profile',br,br,
        'profile 2',br,
        'dump profile',br,br,
        start_form({-action=>'index.cgi',-method=>'post',-enctype=>'multipart/form-data'}),
        'CLI PID:',br,
        textarea(-name=>'dump',-rows=>10,-columns=>50),br,
        'Comments:',br,
        textarea(-name=>'comments',-rows=>5,-columns=>50),br,
        'New File Name:',br,
        hidden({-value=>'submit',-name=>'mode',-override=>1}),p,
        'Select the Blackbox Screenshot: ',input({-type=>'file',-name=>'incoming_file'}),p,"\n",
        input({-type=>'submit',-name=>'Submit',-value=>'Post'}),"\n",
        end_form;
}
a217 8
sub print_pid_table {
  $query = new CGI;
  $upload_filehandle = $query->upload("incoming_file");
  open (UPLOADFILE, ">$dir_full/$file");
  while ( <$upload_filehandle> ) {
    print UPLOADFILE;
  }
  close UPLOADFILE;
d219 16
a234 7
  @@dump = split/(\n)/,$dump;
  print NEW '<b>PID Settings for this trial:</b>',p;
  foreach $line(@@dump) {
    (undef,undef,$key,undef,undef,undef,$val) = split/(\s+)/,$line;
    next if (!$key);
    #print "key=$key: val=$val\n",br;
    $$key = $val;
a235 30
  print NEW p,start_table({-border=>1,-cellpadding=>3}),"\n";
  print NEW start_Tr,"\n";
  print NEW th({-bgcolor=>'#b4b4b4'},font({-color=>'#FFFFFF'},'Axis')),th({-bgcolor=>'#b4b4b4'},font({-color=>'#FFFFFF'},'Proportional')),th({-bgcolor=>'#b4b4b4'},font({-color=>'#FFFFFF'},'Integral')),th({-bgcolor=>'#b4b4b4'},font({-color=>'#FFFFFF'},'Derivative')),th({-bgcolor=>'#b4b4b4'},font({-color=>'#FFFFFF'},'Feedforward')),"\n";
  print NEW end_Tr,"\n";
  
  print NEW start_Tr,td({-width=>80,-bgcolor=>'#d67b7b'},'ROLL'),"\n";
  foreach ('roll_p_gain','roll_i_gain','roll_d_gain','roll_f_gain') {
    print NEW td({-align=>'right',-width=>90},$$_),"\n";
  }
  print NEW end_Tr,"\n";

  print NEW start_Tr,"\n",td({-width=>80,-bgcolor=>'#7ed67b'},'PITCH'),"\n";
  foreach ('pitch_p_gain','pitch_i_gain','pitch_d_gain','pitch_f_gain') {
    print NEW td({-align=>'right'},$$_),"\n";
  }
  print NEW end_Tr,"\n";

  print NEW start_Tr,"\n",td({-width=>80,-bgcolor=>'#7b86d6'},'YAW'),"\n";
  foreach ('yaw_p_gain','yaw_i_gain','yaw_d_gain','yaw_f_gain') {
    if ($val) { $val = $$_ } else { $val = '0' }
    print NEW td({-align=>'right'},$$_),"\n";
  }

  print NEW start_Tr,"\n",td({-width=>80,-bgcolor=>'#d4af7d'},'GOV');
  foreach ('gov_p_gain','gov_i_gain','gov_d_gain','gov_f_gain') {
    if ($val) { $val = $$_ } else { $val = '0' }
    print NEW td({-align=>'right'},$$_),"\n";
  }
  print NEW end_Tr,"\n";
  print NEW end_table,"\n";
d238 1
a238 42
sub print_report_header {
  if ($file =~ /RTFL_BLACKBOX_LOG_(\w+_\d)_(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})\d{2}\.png/) {
      my $model = $1;
      my $year  = $2;
      my $month = $3;
      my $day   = $4;
      my $hour  = $5;
      my $minute = $6;
      print NEW "<table width=100% border=0>\n";
      print NEW "<tr>\n";
      print NEW "<th>Model: $model</th>\n";
      print NEW "<th>Date: $month/$day/$year</th>\n";
      print NEW "<th>Time: $hour:$minute</th>\n";
      print NEW "</tr>\n";
      print NEW "</table>\n";
  } elsif ($file =~ /RTFL_BLACKBOX_LOG_(\w+_\d)_(\d{4})(\d{2})(\d{2})_(\d{2})(\d{2})(\d{2})-P(\d)\.png/) {
      my $model = $1;
      my $year  = $2;
      my $month = $3;
      my $day   = $4;
      my $hour  = $5;
      my $minute = $6;
      my $seconds = $7;
      my $profile = $8;
      print NEW "<table width=100% border=0>\n";
      print NEW "<tr>\n";
      print NEW "<th>Model: $model</th>\n";
      print NEW "<th>Profile: Profile $profile</th>\n";
      print NEW "<th>Date: $month/$day/$year</th>\n";
      print NEW "<th>Time: $hour:$minute</th>\n";
      print NEW "</tr>\n";
      print NEW "</table>\n";
  } else {
      print NEW "<table width=100% border=0>\n";
      print NEW "<tr>\n";
      print NEW "<th>Model: unknown</th>\n";
      print NEW "<th>Date: unknown</th>\n";
      print NEW "<th>Time: unknown</th>\n";
      print NEW "</tr>\n";
      print NEW "</table>\n";
  }
}
d240 17
a256 4
sub print_bblog {
  print NEW '<b>Blackbox Log (Click to Enlarge):</b>',p,"\n";
  print NEW a({-href=>"$dir_http/images/$file"},img({-width=>590,-height=>316,-src=>"$dir_http/images/$file"})),"\n";
}
a257 9
sub print_comments {
  @@comments = split/(\n)/,$comments;
  print NEW '<b>Comments:</b><p>',"\n";
  foreach $line(@@comments) {
    chomp;
    next if ($line eq " ");
    $line =~ s/(\-)/\<li\>/;
    print NEW "$line\n";
  }
@


1.1
log
@Initial revision
@
text
@d8 4
a11 7
my $show_all = param('show_all');
my $diff_only = param('diff_only');
my $pids_only = param('pids_only');
my $step = param('step');
$logo_font2 = 'FFB400';
$page_desc = 'RotorFlight configuration checker';
$auc = $ftc = $bsc = '5D5C61';
d13 5
a17 2
$basedir = '/var/www/www.rcflightpath.com/heli/configs';
$cgipath = "$basedir/index.cgi";
d19 20
a38 1
charset('UTF-8');
d40 9
a48 1
print header;
d50 1
a50 2
if (-e 'style.css') {
  $style = "$basedir/style.css";
d52 1
a52 2
  #$style = '/var/www/www.rcflightpath.com/style.css';
  $style = '/style.css';
d55 19
a73 159
print  start_html(
          -title => "$title",
          -style => {'src' => $style},
          -meta=> {'viewport'=>'width=device-width, initial-scale=1.0','description'=>$page_desc}
        );

print "<!-- Google tag (gtag.js) -->
      <script async src='https://www.googletagmanager.com/gtag/js?id=G-3D6XXHE4VQ'></script>
      <script>
        window.dataLayer = window.dataLayer || [];
        function gtag(){dataLayer.push(arguments);}
        gtag('js', new Date());
        gtag('config', 'G-3D6XXHE4VQ');
      </script>";

# TOP TITLE AREA

  my $mod_time = (stat($cgipath))[9];
  my ($sec, $min, $hour, $mday, $mon, $year) = localtime($mod_time);

  @@months = qw /null Jan Feb Mar Apr May Jun Jul Aug Sep Oct Nov Dec/;
  $mon++;  # Adjust month (0-based index)
  $year += 1900;  # Adjust year (start from 1900)
  $ampm = 'a.m.';
  $ampm = 'p.m.' if ($hour > 11);
  $hour = "0$hour" if ($hour < 11);
  $min  = "0$min"if ($min < 11);

  print start_table({-border=>0,-cellpadding=>0,-cellspacing=>0,-topmargin=>0,-width=>800}), # MAIN TABLE
          start_Tr,
            start_td({-colspan=>2,-bgcolor=>'#5D5C61'}),
              div({-id=>'title'},
                center(
                  table({-border=>0,-width=>'100%',-background=>'/images/bg.png'}, # TITLE TABLE
                    Tr(
                      td({-align=>'center',-width=>300},
                        img({-border=>0,-height=>143,-width=>300,src=>'/images/logo6.png'})),
                      td({-align=>'center'},
                        h1("<b><font color=white>RC</font> <font color=$logo_font2>FlightPath</font></b>"),
                        h2($title),
                        font({-color=>'white'},"Last updated: $months[$mon] $mday, $year @@ $hour:$min $ampm"),
                      ),
                    )
                  )
                ),
              ),
            end_td, 
          end_Tr;

# LEFT SIDE NAVIGATION

  print   start_Tr,
            start_td({-valign=>'top',-bgcolor=>'#B1A296'}), # NAVBAR HERE
              "<div id='navigation'>\n",
              "<ul>",
              "    <li><a href='/articles/pid-tuning/rotorflight'><font color=$auc><b>RotorFlight Blackbox Tuning</b></font></a></li>",p,"\n",
              "  </ul>","\n",
              "</div>\n\n";
            end_td,




# MAIN PAGE SECTION

  print start_td({-bgcolor=>'#EEE2DC',-valign=>'top'}),
        "<div id='main'>\n";

  &print_content;

  print "</div>\n",
        end_td,"\n",
        end_Tr,"\n",
        end_table,"\n";

  &print_footer;

  print end_html;

sub print_content {
  if ($mode eq 'submit') {

    $file1 = param('dump1');
    $file2 = param('dump2');

    if (($file1 !~ /(\.(txt|dmp))$/)||($file2 !~ /(\.(txt|dmp))$/)) {
      print font({-color=>'red'},'Error: You accidentally selected an invalid file. Please hit your "Back" button and try again');
    } elsif ($file1 eq $file2) {
      print font({-color=>'red'},'Error: You need to choose two <b>different</b> files to activate this program. You accidentally chose the same file. Please hit your "Back" button and try again');
    } elsif (($file1)&&($file2)) {
        $upload_dir = '/var/www/www.rcflightpath.com/heli/configs/RotorFlight/tmp';
        $query = new CGI;
        $upload_filehandle = $query->upload("dump1");
    
        open UPLOADFILE, ">$upload_dir/$file1";
        while ( <$upload_filehandle> ) {
          print UPLOADFILE;
        }
        close UPLOADFILE;
    
        $upload_filehandle = $query->upload("dump2");
        open UPLOADFILE, ">$upload_dir/$file2";
        while ( <$upload_filehandle> ) {
          print UPLOADFILE;
        }
        close UPLOADFILE;
    
        open (FILE1,"$upload_dir/$file1");
        while (<FILE1>) {
          chomp;
          if ($_ =~ /(\=)/) {
            ($key, $val) = split/\=/;
            $key =~ s/^\s+//;
            $val =~ s/^\s+//;
            if ($profile) {
              $key .= "(profile$profile)";
            }
            $db1{$key} = $val;
            #print "key=$key val=$val",br;
          } elsif ($_ =~ /^profile/) {
            (undef,$profile) = split/\s+/;
          } else {
          }
        }
        close FILE1;
    
        open (FILE2,"$upload_dir/$file2");
        while (<FILE2>) {
          chomp;
          if ($_ =~ /(\=)/) {
            ($key, $val) = split/\=/;
            $key =~ s/^\s+//;
            $val =~ s/^\s+//;
            $db2{$key} = $val;
            #print "key=$key val=$val",br;
          }
        }
        close FILE2;
    
        print start_table({-border=>1}),Tr(th('&nbsp;'),th($file1),th($file2));;
        foreach (sort keys %db1) {
          if ($db1{$_} ne $db2{$_}) {
            if ($pids_only) {
              if ($_ =~ /gain/) {
                print Tr(td({-bgcolor=>'#f29090'},$_),td($db1{$_}),td($db2{$_}));
              }
            } else {
              print Tr(td({-bgcolor=>'#f29090'},$_),td($db1{$_}),td($db2{$_}));
            }
          } else {
            if ($show_all) {
              print Tr(td($_),td($db1{$_}),td($db2{$_}));
            }
          }
        }
        print end_table;
    } else {
      print font({-color=>'red'},'Error: You need to choose two files to activate this program. Please hit your "Back" button and try again');
    }
d75 8
d84 72
d157 7
a163 15
    print h3('RotorFlight Config Difference Checking Tool'),p,
          strong('Instructions:'),br,
          'Use the below form to select two different RotorFlight configurations (TXT files) from your computer. Upon hitting "Upload Files", you will be presented with a table of all the configurations of each file and if this program finds any differences in values between the two config files, it will highlight them in RED.',p,
          'Use this tool for quickly finding a difference between 2 RotorFlight config files:',
          li('Between two different models for understanding or debug behavior purposes'),
          li('Between a configuration of the same model saved at an earlier time'),p,
          hr,
          start_form({-action=>'index.cgi',-method=>'post',-enctype=>'multipart/form-data'}),
          'RotorFlight Config File no. 1 (Dump file): ',input({-type=>'file',-name=>'dump1'}),br,
          'RotorFlight Config File no. 2 (Dump file): ',input({-type=>'file',-name=>'dump2'}),br,br,
          hidden({-value=>'submit',-name=>'mode'}),
          input({-type=>'submit',-name=>'show_all',-value=>'Show All'}),
          input({-type=>'submit',-name=>'diff_only',-value=>'Show Diff Only'}),
          input({-type=>'submit',-name=>'pids_only',-value=>'Show PIDs Only'}),
          end_form;
d167 4
a170 19
sub print_footer {

  print br,br,'<footer>',
    start_table({-border=>0}),
      start_Tr,
        start_td,
          font({-size=>'-1'},"DBUG: mode=$mode step=$step show_all=$show_all diff_only=$diff_only,pids_only=$pids_only"),
        end_td,
      end_Tr,
      start_Tr,
        '&nbsp;',
      end_Tr,
      start_Tr,
        start_td({-align=>'center'}),
          font({-size=>'-1'},'&copy; 2024 RC FlightPath RC Flight Training & Build Services | San Fernando Valley, CA'),
        end_td,
      end_Tr,
    end_table,
  '</footer>';
d172 9
@
