X-Git-Url: http://git.rot13.org/?p=huawei.git;a=blobdiff_plain;f=at-chat.pl;fp=at-chat.pl;h=7157a30559d8198da1b9fa5e07c6ac05dd2c40c8;hp=0000000000000000000000000000000000000000;hb=86f97ad79d997e1846fd5c567f13697b369789cf;hpb=9952172f4e84cc1fe59a84052e3c20658c89bf4b 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"; +