#!/usr/bin/perl

use charger_lib;


$cl = new charger_lib;
$cl->set_delay(0.05);
$cl->set_unit(shift || 255);
$cl->set_baud(shift || 9600);
$cl->set_debug();

while(1) {

print "[R]ead, [W]rite, [S]et unit, [Q]uit>";
$ch = <>;
($ch1) = split(//,$ch);
$ch1 = lc $ch1;

if($ch1 eq "w") {
	print "Enter an address>";
	$addr = <>;
	chop($addr);
	$addr = oct($addr) if $addr =~ /^0/;

	print "Enter data>";
	$data = <>;
	chop($data);
	while(($reply = $cl->write_ram($addr,$data))) {};
	print "reply: $read\n";
} elsif($ch1 eq "s") {
	print "Enter a unit id>";
	$unit = <>;
	chop($unit);
	$cl->set_unit($unit);
} elsif($ch1 eq "r") {
	print "Enter an address>";
	$addr = <>;
	chop($addr);
	$addr = oct($addr) if $addr =~ /^0/;
	$reply = $cl->read_ram($addr);
	print "reply: $reply\n";
} elsif($ch1 eq "q") {
	exit(0);
} else {
	print "Unknown cmd: $ch1\n";
}


}


