#!/usr/bin/perl
##
##

use CGI;
$CGI::LIST_CONTEXT_WARN = 0;

$q = new CGI;
print $q->header(-charset=> "UTF-8",);
open(NodeFILE, "< /var/www/node.conf") or die("Error: $!");
my $match_pattern = '^\s*(#.*|)$';
while (my $line = <NodeFILE>) {
        chomp $line;
        if ($line !~ $match_pattern) {
		if (substr($line , 0, 13) eq "NODE_VENDERID") {
			my @list = split (/=/, $line);
			$VenderID = pop @list;
		}
		if (substr($line , 0, 14) eq "NODE_PRODUCTID") {
			my @list = split (/=/, $line);
			$ProductID = pop @list;
		}
		if (substr($line , 0, 14) eq "NODE_TX_INVERT") {
			my @list = split (/=/, $line);
			$tx_invert = pop @list;
		}
		if (substr($line , 0, 14) eq "NODE_RX_INVERT") {
			my @list = split (/=/, $line);
			$rx_invert = pop @list;
		}
		if (substr($line , 0, 13) eq "NODE_TX_DELAY") {
			my @list = split (/=/, $line);
			$txdelay = pop @list;
		}
        }
    }
close (DvmegaFILE);
print <<'EOF';
<HTML lang="ja">
<HEAD>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<META http-equiv="Content-Style-Type" content="text/css">
<TITLE>DVMEGA Setting</TITLE>
<script>
function Store() {
document.Node_set.action="/cgi-bin/NodeStore";
document.Node_set.target="_top";
document.Node_set.method="post";
document.Node_set.submit();
}
</script>
</HEAD>
<BODY>
<form name="Node_set">
<br>NODE Adapter設定</br>
EOF
print "ベンダーID<input type=\"text\" name=\"VenderID\" value=\"" . $VenderID . "\" size=\"4\"><br>\n";
print "プロダクトID<input type=\"text\" name=\"ProductID\" value=\"" . $ProductID . "\" size=\"4\"><br>\n";
print "送信極性反転<input type=\"text\" name=\"tx_invert\" value=\"" . $tx_invert . "\" size=\"4\"><br>\n";
print "受信極性反転<input type=\"text\" name=\"rx_invert\" value=\"" . $rx_invert . "\" size=\"4\"><br>\n";
print "送信遅延<input type=\"text\" name=\"txdelay\" value=\"" . $txdelay . "\" size=\"4\">ミリ秒<br>\n";
print <<'EOF';
<button type="button" onclick="Store()">登録</button><br>
登録をクリックしますと設定を保存後、ラズベリーパイが再起動されます。
</form>
EOF
print $q->end_html;

