From b24086f2702630d50b9a34173f8219b1bb364fb9 Mon Sep 17 00:00:00 2001 From: Dobrica Pavlinusic Date: Fri, 27 Jan 2012 14:07:01 +0100 Subject: [PATCH] chat with qualcomm modem --- qcom-chat.pl | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100755 qcom-chat.pl diff --git a/qcom-chat.pl b/qcom-chat.pl new file mode 100755 index 0000000..71fb97c --- /dev/null +++ b/qcom-chat.pl @@ -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"; + -- 2.20.1