--- nfo/perl/scripts/cellcom/bin/cellcom.pl 2003/04/16 12:24:20 1.1 +++ nfo/perl/scripts/cellcom/bin/cellcom.pl 2003/04/17 07:22:44 1.2 @@ -1,193 +1,121 @@ #!/usr/bin/perl -# $Id: cellcom.pl,v 1.1 2003/04/16 12:24:20 joko Exp $ +# $Id: cellcom.pl,v 1.2 2003/04/17 07:22:44 joko Exp $ # $Log: cellcom.pl,v $ +# Revision 1.2 2003/04/17 07:22:44 joko +# moved code to Data::Storage::Handler::Cellphone +# # Revision 1.1 2003/04/16 12:24:20 joko # initial commit # -# 1. testing, status, introspection, command-groups, schema -# 2. high-speed phonebook backup -# 3. FollowMe: automagically detect connection, read IMEI -# 4. protocol-declaration in xml (it's a "service"!) +# cellcom - or Cellular2Pim +# for requirements, features and todos see cellrap.pl use strict; use warnings; -use Win32::SerialPort; -#use Unicode::String qw(ucs2 ucs4 latin1); +use lib '../../../libs'; use Data::Dumper; +use Data::Storage::Handler::Cellphone; -#require 'modules/me45/ME45.pm'; -#my $me45 = ME45->new('COM1'); -#$me45->get_vendor(); - -my $port = 'COM1'; -my $quiet = 1; - -my $cellular = new Win32::SerialPort($port, $quiet); -#$cellular->baudrate(57600); - -$cellular->baudrate(9600); -$cellular->databits(8); -$cellular->parity('none'); -$cellular->stopbits(1); +my $cellular = Data::Storage::Handler::Cellphone->new( baudrate => 115200, command_type => 'GSM' ); -$cellular->error_msg(1); -$cellular->user_msg(1); - -$cellular->debug(1); # toggle command echo mode on/off -#$cellular->write('ATE0' . "\r\n"); -#$cellular->write('ATE1' . "\r\n"); +#$cellular->send('ATE0' . "\r\n"); +#$cellular->send('ATE1' . "\r\n"); # send dummy AT -#$cellular->write('AT' . "\r\n"); +#$cellular->send('AT' . "\r\n"); # query vendor/manufacturer info -#$cellular->write('AT+CGMI' . "\r\n"); +#$cellular->send('AT+CGMI' . "\r\n"); # model id code -#$cellular->write('AT+CGMM' . "\r\n"); +#$cellular->send('AT+CGMM' . "\r\n"); # gsm telephone version -#$cellular->write('AT+CGMR' . "\r\n"); +#$cellular->send('AT+CGMR' . "\r\n"); # query the cellulars clock -#$cellular->write('AT+CCLK?' . "\r\n"); -#$cellular->write('AT+CCLK?' . "\r\n"); +#$cellular->send('AT+CCLK?' . "\r\n"); +#$cellular->send('AT+CCLK?' . "\r\n"); # query the serial number (IMEI) -#$cellular->write('AT+CGSN' . "\r\n"); -#$cellular->write('AT+GSN' . "\r\n"); +#$cellular->send('AT+CGSN' . "\r\n"); +#$cellular->send('AT+GSN' . "\r\n"); +$cellular->send('GSN'); # phone status -#$cellular->write('AT+CPAS' . "\r\n"); +#$cellular->send('AT+CPAS' . "\r\n"); # price per unit -#$cellular->write('AT+CPUC?' . "\r\n"); +#$cellular->send('AT+CPUC?' . "\r\n"); # query capabilities -#$cellular->write('AT+GCAP' . "\r\n"); +#$cellular->send('AT+GCAP' . "\r\n"); # sms stuff -#$cellular->write('AT^SMGL=4' . "\r\n"); -#$cellular->write('AT^SMGR=3' . "\r\n"); +#$cellular->send('AT^SMGL=4' . "\r\n"); +#$cellular->send('AT^SMGR=3' . "\r\n"); # off -#$cellular->write('AT^SMSO' . "\r\n"); +#$cellular->send('AT^SMSO' . "\r\n"); # database access -#$cellular->write('AT^SDBR=90' . "\r\n"); +#$cellular->send('AT^SDBR=90' . "\r\n"); # output signal quality -#$cellular->write('AT+CSQ' . "\r\n"); +#$cellular->send('AT+CSQ' . "\r\n"); # telephone book access -#$cellular->write('AT+CPBR=93' . "\r\n"); +#$cellular->send('AT+CPBR=93' . "\r\n"); # play signal tone -#$cellular->write('AT^SPST=0,1' . "\r\n"); +#$cellular->send('AT^SPST=0,1' . "\r\n"); # use GSM charset -#$cellular->write('AT+CSCS=GSM' . "\r\n"); -#$cellular->write('AT+CSCS=UCS2' . "\r\n"); +#$cellular->send('AT+CSCS=GSM' . "\r\n"); +#$cellular->send('AT+CSCS=UCS2' . "\r\n"); # organizer database (vcalendar entries in hex) # > AT^SBNW=? # ^SBNW: ("bmp",(0-3)),("mid",(0-5)),("vcf",(0-500)),("vcs",(0-50)),("t9d",(0)),("bmx",(4)) -#$cellular->write('AT^SBNW=?' . "\r\n"); -#$cellular->write('AT^SBNR="vcs",3' . "\r\n"); -#$cellular->write('AT^SBNR="bmp",2' . "\r\n"); -#$cellular->write('AT^SBNR="vcf",55' . "\r\n"); -$cellular->write('AT^SBNR="vcf",38' . "\r\n"); -#$cellular->write('AT^SBNR="vcf",124' . "\r\n"); -#$cellular->write('AT^SBNR="vcf",125' . "\r\n"); +#$cellular->send('AT^SBNW=?' . "\r\n"); +#$cellular->send('AT^SBNR="vcs",3' . "\r\n"); +#$cellular->send('AT^SBNR="bmp",2' . "\r\n"); +#$cellular->send('AT^SBNR="vcf",55' . "\r\n"); +#$cellular->send('AT^SBNR="vcf",40' . "\r\n"); +#$cellular->send('AT^SBNR="vcf",124' . "\r\n"); +#$cellular->send('AT^SBNR="vcf",125' . "\r\n"); # phonebook -search and -lookup ... # ... by letter -#$cellular->write('AT^SPBC=K' . "\r\n"); -#$cellular->write('AT^SPBC=K' . "\r\n"); +#$cellular->send('AT^SPBC=K' . "\r\n"); +#$cellular->send('AT^SPBC=K' . "\r\n"); # ... by index -#$cellular->write('AT^SPBG=38' . "\r\n"); +#$cellular->send('AT^SPBG=38' . "\r\n"); # select different telephone book -#$cellular->write('AT^SPBS=?' . "\r\n"); -#$cellular->write('AT^SPBS=MC' . "\r\n"); -#$cellular->write('AT^SPBG=?' . "\r\n"); -#$cellular->write('AT^SPBC=?' . "\r\n"); - -#$cellular->write('AT^SPBS=CS' . "\r\n"); -#$cellular->write('AT^SPBG=38' . "\r\n"); - +#$cellular->send('AT^SPBS=?' . "\r\n"); +#$cellular->send('AT^SPBS=MC' . "\r\n"); +#$cellular->send('AT^SPBG=?' . "\r\n"); +#$cellular->send('AT^SPBC=?' . "\r\n"); -# sleep a bit -# TODO: use a more granular timer -sleep 1; +#$cellular->send('AT^SPBS=CS' . "\r\n"); +#$cellular->send('AT^SPBG=38' . "\r\n"); -#my $response = $cellular->input(); -my $res_count; -my $res_payload; -($res_count, $res_payload) = $cellular->read(500); -print "> ", $res_payload, "\n"; - -if (my $data = bfb::extract($res_payload)) { - print "-" x 30, "\n"; - print $data, "\n"; - print "-" x 30, "\n"; -} - -$cellular->close(); -undef $cellular; - - - -package bfb; - -use Data::Dumper; +$cellular->response_read(); -sub decode { - my $data = shift; - my @buf; - for (my $i = 0; $i <= length($data); $i = $i + 2) { - my $nybble = substr($data, $i, 2); - push @buf, chr(hex($nybble)); - } - return join('', @buf); -} - -sub extract { - my $data = shift; - my @parts = split("\r\n", $data); - - #print Dumper(@parts); - #exit; - - my $res = ''; - -BLOCK: - - # ignore first two lines of each block - shift @parts; - shift @parts; - - if (my $payload = shift @parts) { - $res .= $payload; - } - - goto BLOCK if @parts; - - my $res_dec = bfb::decode($res); - - return $res_dec; -} +$cellular->send('SDBR=90', 'SIEMENS'); +$cellular->response_read(); 1; __END__