From: Dobrica Pavlinusic Date: Sun, 29 Jan 2012 11:58:35 +0000 (+0100) Subject: rename AT chat script X-Git-Url: http://git.rot13.org/?p=huawei.git;a=commitdiff_plain;h=86f97ad79d997e1846fd5c567f13697b369789cf rename AT chat script --- diff --git a/at-chat.pl b/at-chat.pl new file mode 100755 index 0000000..7157a30 --- /dev/null +++ b/at-chat.pl @@ -0,0 +1,87 @@ +#!/usr/bin/perl +use warnings; +use strict; + +use Device::SerialPort; +use Data::Dump qw(dump); + +my $device = $ENV{DEVICE} || '/dev/ttyUSB0'; + +my $port = Device::SerialPort->new( $device ) || die "$device: $!"; +$port->baudrate(115200) || die "fail $device baudrate"; +$port->parity("none") || die "fail $device parity"; +$port->databits(8) || die "fail $device databits"; +$port->stopbits(1) || die "fail $device stopbits"; +$port->handshake("rts") || die "fail $device handshake"; + +$port->write_settings || die "no $device settings"; + +$port->user_msg(1); +$port->error_msg(1); +$port->debug(1); + +$port->read_char_time(3000); # 5 s char timeout +$port->read_const_time(3000); # 1 s read timeout + +while ( my $drain = $port->input ) { + warn "# drain $drain\n# /drain\n"; +} + + +warn "## using $device\n"; + +sub c { + my ($cmd,$message) = @_; + print STDERR ">>> $cmd >>> $message\n"; + $port->write("$cmd\r"); +# $port->write_done(1); # flush + $port->write_drain; + my $ret = $port->read(1); +again: + while ( my $c = $port->input ) { + print STDERR "<<< ",dump($ret . $c), $/; + $ret .= $c; +# last if $c =~ m/^OK\r/; + } + goto again unless $ret =~ s/\r\n(OK|ERROR)\r\n$//s || warn "ERROR: can't find OK or ERROR status!\n"; + $ret =~ s/^[\r\n]+//; + print "$cmd [$message] = $ret\n"; + return $ret; +} + +c 'ATE0' => 'echo off'; +#c 'ATZ' => 'reset'; +# +c 'ATI' => 'info'; + +c 'AT+CGMI' => 'manufacturer'; + +c 'AT+CGMM' => 'model'; + +c 'AT+CGMR' => 'revision'; + +c 'AT+CGSN' => 'serial'; + +c 'AT+GCAP' => 'capabilities'; + +c 'AT+CIMI' => 'IMSI'; + +c 'AT+CNUM' => 'MSISDN'; + +#c 'AT+COPS=?' => 'operators'; # times out + +c 'AT+CLCK=?' => 'facility lock'; + +c 'AT^HWVER' => 'hardware version'; + +c 'AT^CVOICE?' => 'is voice enabled?'; + +c 'AT^DDSETEX=?' => 'voice output'; + +c 'AT^SYSINFO' => 'sys info'; + + +$port->close || die "can't close port $!"; + +warn "## $device closed\n"; + diff --git a/qcom-chat.pl b/qcom-chat.pl deleted file mode 100755 index 7157a30..0000000 --- a/qcom-chat.pl +++ /dev/null @@ -1,87 +0,0 @@ -#!/usr/bin/perl -use warnings; -use strict; - -use Device::SerialPort; -use Data::Dump qw(dump); - -my $device = $ENV{DEVICE} || '/dev/ttyUSB0'; - -my $port = Device::SerialPort->new( $device ) || die "$device: $!"; -$port->baudrate(115200) || die "fail $device baudrate"; -$port->parity("none") || die "fail $device parity"; -$port->databits(8) || die "fail $device databits"; -$port->stopbits(1) || die "fail $device stopbits"; -$port->handshake("rts") || die "fail $device handshake"; - -$port->write_settings || die "no $device settings"; - -$port->user_msg(1); -$port->error_msg(1); -$port->debug(1); - -$port->read_char_time(3000); # 5 s char timeout -$port->read_const_time(3000); # 1 s read timeout - -while ( my $drain = $port->input ) { - warn "# drain $drain\n# /drain\n"; -} - - -warn "## using $device\n"; - -sub c { - my ($cmd,$message) = @_; - print STDERR ">>> $cmd >>> $message\n"; - $port->write("$cmd\r"); -# $port->write_done(1); # flush - $port->write_drain; - my $ret = $port->read(1); -again: - while ( my $c = $port->input ) { - print STDERR "<<< ",dump($ret . $c), $/; - $ret .= $c; -# last if $c =~ m/^OK\r/; - } - goto again unless $ret =~ s/\r\n(OK|ERROR)\r\n$//s || warn "ERROR: can't find OK or ERROR status!\n"; - $ret =~ s/^[\r\n]+//; - print "$cmd [$message] = $ret\n"; - return $ret; -} - -c 'ATE0' => 'echo off'; -#c 'ATZ' => 'reset'; -# -c 'ATI' => 'info'; - -c 'AT+CGMI' => 'manufacturer'; - -c 'AT+CGMM' => 'model'; - -c 'AT+CGMR' => 'revision'; - -c 'AT+CGSN' => 'serial'; - -c 'AT+GCAP' => 'capabilities'; - -c 'AT+CIMI' => 'IMSI'; - -c 'AT+CNUM' => 'MSISDN'; - -#c 'AT+COPS=?' => 'operators'; # times out - -c 'AT+CLCK=?' => 'facility lock'; - -c 'AT^HWVER' => 'hardware version'; - -c 'AT^CVOICE?' => 'is voice enabled?'; - -c 'AT^DDSETEX=?' => 'voice output'; - -c 'AT^SYSINFO' => 'sys info'; - - -$port->close || die "can't close port $!"; - -warn "## $device closed\n"; -