#!/usr/bin/perl
use Getopt::Std;
use Device::Gsm::Pdu;
# defaults
$opt_i = "/dev/ttyUSB2";
$opt_o = "/dev/ttyUSB0";
my $USAGE = <<__EOU;
Usage: $0 [-i input_port] [-o output_port] [-n] [-h] [-v] ussd_msg
Description:
Send and receive 7-bit PDU-encoded USSD messages.
Written and tested to work for (just mine) Huawei E1550 GSM/UMTS USB modem.
Options:
-i port Port to receive data from. Default: $opt_i
-o port Port to send AT commands to. Default: $opt_o
-n Do not send any data to port. Useful with -v.
-h Print this help.
-v Be verbose.
__EOU
sub HELP_MESSAGE {print "$USAGE\n"; exit;}
sub VERSION_MESSAGE {};
getopts ('i:o:hnv');
HELP_MESSAGE() and exit if (! $ARGV[0]) or defined($opt_h);
print "USSD MSG: $ARGV[0]\n" if $opt_v;
my $ussd_req = Device::Gsm::Pdu::encode_text7($ARGV[0]);
$ussd_req =~ s/^..//;
print "PDU ENCODED: $ussd_req\n" if $opt_v;
my $ussd_reply;
if (! $opt_n) {
open (SENDPORT, '+<', $opt_o) or die "Can't open '$opt_o': $!\n";
print SENDPORT 'AT+CUSD=1,',$ussd_req,",15\r\n";
close SENDPORT;
open (RCVPORT, $opt_i) or die "Can't open '$opt_i': $!\n";
print "Waiting for USSD reply...\n" if $opt_v;
while (<RCVPORT>) {
chomp;
die "USSD ERROR\n" if $_ eq "+CUSD: 2";
if (/^\+CUSD: 0,\"([A-F0-9]+)\"/) {
$ussd_reply = $1;
print "PDU USSD REPLY: $ussd_reply\n" if $opt_v;
last;
}
print "Got unknown USSD message: $_\n" if /^\+CUSD:/ and $opt_v;
}
}
if ($ussd_reply) {
$decoded_ussd_reply = Device::Gsm::Pdu::decode_text7('00'.$ussd_reply);
print STDOUT "USSD REPLY: $decoded_ussd_reply\n";
}
else {print "No USSD reply!\n";}
ussd_msg пишется привычным способом:
# script.pl "*111#"
USSD REPLY: Na Vashomu rahunku 6.66 grn.
upd: если не расшифровывается USSD-ответ, замените вызов функции decode_text7('00'.$ussd_reply) на pdu_to_latin1($ussd_reply)
(без нолей)
Anonymous
January 9 2011, 22:03:57 UTC 1 year ago
Anonymous
May 12 2011, 20:52:45 UTC 1 year ago
У меня возникла проблема - PDU код не расшифровуется.
sudo ./perl.pl -v *121#
USSD MSG: *121#
PDU ENCODED: AA982C3602
Waiting for USSD reply...
PDU USSD REPLY: 4937BD2C7797E9BAD91114ABD56A38980BB714B3
USSD REPLY:
Дайте совет.
May 13 2011, 22:00:24 UTC 1 year ago
А так, подсмотреть можно, например, на странице модуля: http://search.cpan.org/~cosimo/Device-G
Кстати, нашёл у себя ошибки, вместо $opt_r и $opt_s должны быть $opt_i и $opt_o соответственно.
May 30 2011, 17:48:22 UTC 11 months ago
Anonymous
June 12 2011, 07:21:38 UTC 11 months ago
root@debian-laptop:/# /home/nn/Desktop/ussd -v "*100#"
USSD MSG: *100#
Undefined subroutine &Device::Gsm::Pdu::encode_text7 called at /home/nn/Desktop/ussd line 32
Как сделать чтоб заработало?
June 12 2011, 10:46:12 UTC 11 months ago
Anonymous
August 2 2011, 18:21:24 UTC 9 months ago
baktus@brasus:~$ perl huawei-ussd.pl
Can't locate Device/Gsm/Pdu.pm in @INC (@INC contains: /etc/perl /usr/local/lib/perl/5.10.1 /usr/local/share/perl/5.10.1 /usr/lib/perl5 /usr/share/perl5 /usr/lib/perl/5.10 /usr/share/perl/5.10 /usr/local/lib/site_perl .) at huawei-ussd.pl line 4.
BEGIN failed--compilation aborted at huawei-ussd.pl line 4.
ubuntu 11.04 kernel 2.6.38-10
спасибо заранее
August 2 2011, 23:30:58 UTC 9 months ago
perl -MCPAN -e 'install Device::Gsm::Pdu'
Anonymous
September 9 2011, 11:58:28 UTC 8 months ago
скрипт не работает для gobi 2000
Установилperl -MCPAN -e 'install Device::Gsm::Pdu'
Appending installation info to /usr/lib/perl5/i386-linux/perllocal.pod
COSIMO/Device-Gsm-1.58.tar.gz
/usr/bin/make install -- OK
Warning (usually harmless): 'YAML' not installed, will not store persistent state
Затем запустил скрипт. И он завис для модема gobi 2000 /dev/ttyUSB2:
$ ./script.pl -v "*100#"
USSD MSG: *100#
PDU ENCODED: AA180C3602
Waiting for USSD reply...
Как подправить скрипт для этого модема?
September 9 2011, 15:03:40 UTC 8 months ago
Re: скрипт не работает для gobi 2000
Не знаю, у меня нет такого модема чтобы проверить что-либо. Пообщайтесь с модемом через что-нибудь наподобие minicom.September 19 2011, 09:14:19 UTC 8 months ago
Я поправил кое-что, иначе у меня не работало. Вот исправленная версия.
(Кстати, у вас в тексте куда-то делись все знаки + и *.)
#!/usr/bin/perl use Getopt::Std; use Device::Gsm::Pdu; use Fcntl; # defaults $opt_i = "/dev/ttyUSB2"; $opt_o = "/dev/ttyUSB2"; my $USAGE = <<__EOU; Usage: $0 [-i input_port] [-o output_port] [-n] [-h] [-v] ussd_msg Description: Send and receive 7-bit PDU-encoded USSD messages. Written and tested for Huawei E1550 GSM/UMTS USB modem. Edited for Huavei E173 modem (Megafon) Options: -i port Port to receive data from. Default: $opt_i -o port Port to send AT commands to. Default: $opt_o -n Do not send any data to port. Useful with -v. -h Print this help. -v Be verbose. __EOU sub HELP_MESSAGE {print "$USAGE\n"; exit;} sub VERSION_MESSAGE {}; getopts ('i:o:hnv'); HELP_MESSAGE() and exit if (! $ARGV[0]) or defined($opt_h); print "USSD MSG: $ARGV[0]\n" if $opt_v; my $ussd_req = Device::Gsm::Pdu::encode_text7($ARGV[0]); $ussd_req =~ s/^..//; print "PDU ENCODED: $ussd_req\n" if $opt_v; my $ussd_reply; if (! $opt_n) { sysopen(SENDPORT, $opt_o, O_NONBLOCK|O_RDWR) or die "Can't open '$opt_o': $!\n"; print SENDPORT 'AT+CUSD=1,',$ussd_req,",15\r\n"; close SENDPORT; open (RCVPORT, $opt_i) or die "Can't open '$opt_i': $!\n"; print "Waiting for USSD reply...\n" if $opt_v; while () { chomp; die "USSD ERROR\n" if $_ eq "+CUSD: 2"; if (/^\+CUSD: 0,\"([A-F0-9]*)\"/) { $ussd_reply = $1; print "PDU USSD REPLY: $ussd_reply\n" if $opt_v; last; } print "Got unknown USSD message: $_\n" if /^\+CUSD:/ and $opt_v; } } if ($ussd_reply) { $decoded_ussd_reply = Device::Gsm::Pdu::decode_text_UCS2('00'.$ussd_reply); print STDOUT "USSD REPLY: $decoded_ussd_reply\n"; } else {print "No USSD reply!\n";}September 19 2011, 18:05:53 UTC 8 months ago
Anonymous
May 8 2012, 22:36:44 UTC 1 week ago