chat with qualcomm modem
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 27 Jan 2012 13:07:01 +0000 (14:07 +0100)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 27 Jan 2012 13:07:01 +0000 (14:07 +0100)
qcom-chat.pl [new file with mode: 0755]

diff --git a/qcom-chat.pl b/qcom-chat.pl
new file mode 100755 (executable)
index 0000000..71fb97c
--- /dev/null
@@ -0,0 +1,72 @@
+#!/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(1000);  # 0.1 s char timeout
+$port->read_const_time(500); # 0.5 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);
+       while ( my $c = $port->input ) {
+               print STDERR "<<< ",dump($ret . $c), $/;
+               $ret .= $c;
+#              last if $c =~ m/^OK\r/;
+       }
+       $ret =~ s/^[\r\n]+//;
+       $ret =~ s/\r\nOK\r\n$// || warn "ERROR: missing OK";
+       print "$cmd [$message] = $ret\n";
+       return $ret;
+}
+
+c 'ATE0' => 'echo off';
+#c 'ATZ' => 'reset';
+#
+c 'ATI'  => 'info';
+
+c 'AT+CGMI'  => 'CGMI';
+
+c 'AT+CGMM'  => 'CGMM';
+
+c 'AT+CGMR'  => 'CGMR';
+
+c 'AT+CIMI'  => 'IMSI';
+
+c 'AT+CGSN'  => 'CGSN';
+
+c 'AT^CVOICE?' => 'is voice enabled?';
+
+
+$port->close || die "can't close port $!";
+
+warn "## $device closed\n";
+