#!/usr/bin/perl
#just checks if ISDN Modememulation is talking
#THIS TESTS NOT IF IT'S WORKING!!

use Fcntl;

$TimeOut = 5;  # max. number of seconds to wait for input

sysopen(ISDN, "/dev/ttyI0", O_RDWR() | O_NONBLOCK()) || die "$!";

Send("ATZ\n");		#attention
Send("ATI\n");		#ISDN Information
Send("AT&E502969");	#Set MSN == 1234
Send("ATI2\n");		#last connection report
sleep(3);

close ISDN;

sub Send()
{
  my $t = time();
  my $s = "";

  print(">>> ", @_, "\n");
  print(ISDN @_);
  while (1) {
        if (read(ISDN, $c, 1)) {
           $t = time();
           next if ($c eq "\r");
           #print $c;
           $s .= $c;
           if ($c eq "\n") {
	      ($s =~ /^(\s)*$/) or print ($s);
              last if ($s eq "OK\n");
              $s = "";
              }
           }
        else {
           last if (time() - $t > $TimeOut);
           }
        }
}


