2 |
|
|
3 |
# $Id$ |
# $Id$ |
4 |
# $Log$ |
# $Log$ |
5 |
|
# Revision 1.2 2003/04/17 07:22:44 joko |
6 |
|
# moved code to Data::Storage::Handler::Cellphone |
7 |
|
# |
8 |
# Revision 1.1 2003/04/16 12:24:20 joko |
# Revision 1.1 2003/04/16 12:24:20 joko |
9 |
# initial commit |
# initial commit |
10 |
# |
# |
11 |
|
|
12 |
|
|
13 |
# 1. testing, status, introspection, command-groups, schema |
# cellcom - or Cellular2Pim |
14 |
# 2. high-speed phonebook backup |
# for requirements, features and todos see cellrap.pl |
|
# 3. FollowMe: automagically detect connection, read IMEI |
|
|
# 4. protocol-declaration in xml (it's a "service"!) |
|
15 |
|
|
16 |
|
|
17 |
use strict; |
use strict; |
18 |
use warnings; |
use warnings; |
19 |
|
|
20 |
use Win32::SerialPort; |
use lib '../../../libs'; |
|
#use Unicode::String qw(ucs2 ucs4 latin1); |
|
21 |
|
|
22 |
use Data::Dumper; |
use Data::Dumper; |
23 |
|
use Data::Storage::Handler::Cellphone; |
24 |
|
|
25 |
#require 'modules/me45/ME45.pm'; |
my $cellular = Data::Storage::Handler::Cellphone->new( baudrate => 115200, command_type => 'GSM' ); |
|
#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); |
|
26 |
|
|
|
$cellular->error_msg(1); |
|
|
$cellular->user_msg(1); |
|
|
|
|
|
$cellular->debug(1); |
|
27 |
|
|
28 |
|
|
29 |
# toggle command echo mode on/off |
# toggle command echo mode on/off |
30 |
#$cellular->write('ATE0' . "\r\n"); |
#$cellular->send('ATE0' . "\r\n"); |
31 |
#$cellular->write('ATE1' . "\r\n"); |
#$cellular->send('ATE1' . "\r\n"); |
32 |
|
|
33 |
# send dummy AT |
# send dummy AT |
34 |
#$cellular->write('AT' . "\r\n"); |
#$cellular->send('AT' . "\r\n"); |
35 |
|
|
36 |
# query vendor/manufacturer info |
# query vendor/manufacturer info |
37 |
#$cellular->write('AT+CGMI' . "\r\n"); |
#$cellular->send('AT+CGMI' . "\r\n"); |
38 |
|
|
39 |
# model id code |
# model id code |
40 |
#$cellular->write('AT+CGMM' . "\r\n"); |
#$cellular->send('AT+CGMM' . "\r\n"); |
41 |
|
|
42 |
# gsm telephone version |
# gsm telephone version |
43 |
#$cellular->write('AT+CGMR' . "\r\n"); |
#$cellular->send('AT+CGMR' . "\r\n"); |
44 |
|
|
45 |
|
|
46 |
# query the cellulars clock |
# query the cellulars clock |
47 |
#$cellular->write('AT+CCLK?' . "\r\n"); |
#$cellular->send('AT+CCLK?' . "\r\n"); |
48 |
#$cellular->write('AT+CCLK?' . "\r\n"); |
#$cellular->send('AT+CCLK?' . "\r\n"); |
49 |
|
|
50 |
# query the serial number (IMEI) |
# query the serial number (IMEI) |
51 |
#$cellular->write('AT+CGSN' . "\r\n"); |
#$cellular->send('AT+CGSN' . "\r\n"); |
52 |
#$cellular->write('AT+GSN' . "\r\n"); |
#$cellular->send('AT+GSN' . "\r\n"); |
53 |
|
$cellular->send('GSN'); |
54 |
|
|
55 |
# phone status |
# phone status |
56 |
#$cellular->write('AT+CPAS' . "\r\n"); |
#$cellular->send('AT+CPAS' . "\r\n"); |
57 |
|
|
58 |
# price per unit |
# price per unit |
59 |
#$cellular->write('AT+CPUC?' . "\r\n"); |
#$cellular->send('AT+CPUC?' . "\r\n"); |
60 |
|
|
61 |
# query capabilities |
# query capabilities |
62 |
#$cellular->write('AT+GCAP' . "\r\n"); |
#$cellular->send('AT+GCAP' . "\r\n"); |
63 |
|
|
64 |
# sms stuff |
# sms stuff |
65 |
#$cellular->write('AT^SMGL=4' . "\r\n"); |
#$cellular->send('AT^SMGL=4' . "\r\n"); |
66 |
#$cellular->write('AT^SMGR=3' . "\r\n"); |
#$cellular->send('AT^SMGR=3' . "\r\n"); |
67 |
|
|
68 |
# off |
# off |
69 |
#$cellular->write('AT^SMSO' . "\r\n"); |
#$cellular->send('AT^SMSO' . "\r\n"); |
70 |
|
|
71 |
# database access |
# database access |
72 |
#$cellular->write('AT^SDBR=90' . "\r\n"); |
#$cellular->send('AT^SDBR=90' . "\r\n"); |
73 |
|
|
74 |
# output signal quality |
# output signal quality |
75 |
#$cellular->write('AT+CSQ' . "\r\n"); |
#$cellular->send('AT+CSQ' . "\r\n"); |
76 |
|
|
77 |
# telephone book access |
# telephone book access |
78 |
#$cellular->write('AT+CPBR=93' . "\r\n"); |
#$cellular->send('AT+CPBR=93' . "\r\n"); |
79 |
|
|
80 |
# play signal tone |
# play signal tone |
81 |
#$cellular->write('AT^SPST=0,1' . "\r\n"); |
#$cellular->send('AT^SPST=0,1' . "\r\n"); |
82 |
|
|
83 |
# use GSM charset |
# use GSM charset |
84 |
#$cellular->write('AT+CSCS=GSM' . "\r\n"); |
#$cellular->send('AT+CSCS=GSM' . "\r\n"); |
85 |
#$cellular->write('AT+CSCS=UCS2' . "\r\n"); |
#$cellular->send('AT+CSCS=UCS2' . "\r\n"); |
86 |
|
|
87 |
# organizer database (vcalendar entries in hex) |
# organizer database (vcalendar entries in hex) |
88 |
# > AT^SBNW=? |
# > AT^SBNW=? |
89 |
# ^SBNW: ("bmp",(0-3)),("mid",(0-5)),("vcf",(0-500)),("vcs",(0-50)),("t9d",(0)),("bmx",(4)) |
# ^SBNW: ("bmp",(0-3)),("mid",(0-5)),("vcf",(0-500)),("vcs",(0-50)),("t9d",(0)),("bmx",(4)) |
90 |
#$cellular->write('AT^SBNW=?' . "\r\n"); |
#$cellular->send('AT^SBNW=?' . "\r\n"); |
91 |
#$cellular->write('AT^SBNR="vcs",3' . "\r\n"); |
#$cellular->send('AT^SBNR="vcs",3' . "\r\n"); |
92 |
#$cellular->write('AT^SBNR="bmp",2' . "\r\n"); |
#$cellular->send('AT^SBNR="bmp",2' . "\r\n"); |
93 |
#$cellular->write('AT^SBNR="vcf",55' . "\r\n"); |
#$cellular->send('AT^SBNR="vcf",55' . "\r\n"); |
94 |
$cellular->write('AT^SBNR="vcf",38' . "\r\n"); |
#$cellular->send('AT^SBNR="vcf",40' . "\r\n"); |
95 |
#$cellular->write('AT^SBNR="vcf",124' . "\r\n"); |
#$cellular->send('AT^SBNR="vcf",124' . "\r\n"); |
96 |
#$cellular->write('AT^SBNR="vcf",125' . "\r\n"); |
#$cellular->send('AT^SBNR="vcf",125' . "\r\n"); |
97 |
|
|
98 |
# phonebook -search and -lookup ... |
# phonebook -search and -lookup ... |
99 |
# ... by letter |
# ... by letter |
100 |
#$cellular->write('AT^SPBC=K' . "\r\n"); |
#$cellular->send('AT^SPBC=K' . "\r\n"); |
101 |
#$cellular->write('AT^SPBC=K' . "\r\n"); |
#$cellular->send('AT^SPBC=K' . "\r\n"); |
102 |
# ... by index |
# ... by index |
103 |
#$cellular->write('AT^SPBG=38' . "\r\n"); |
#$cellular->send('AT^SPBG=38' . "\r\n"); |
104 |
|
|
105 |
# select different telephone book |
# select different telephone book |
106 |
#$cellular->write('AT^SPBS=?' . "\r\n"); |
#$cellular->send('AT^SPBS=?' . "\r\n"); |
107 |
#$cellular->write('AT^SPBS=MC' . "\r\n"); |
#$cellular->send('AT^SPBS=MC' . "\r\n"); |
108 |
#$cellular->write('AT^SPBG=?' . "\r\n"); |
#$cellular->send('AT^SPBG=?' . "\r\n"); |
109 |
#$cellular->write('AT^SPBC=?' . "\r\n"); |
#$cellular->send('AT^SPBC=?' . "\r\n"); |
|
|
|
|
#$cellular->write('AT^SPBS=CS' . "\r\n"); |
|
|
#$cellular->write('AT^SPBG=38' . "\r\n"); |
|
|
|
|
110 |
|
|
111 |
# sleep a bit |
#$cellular->send('AT^SPBS=CS' . "\r\n"); |
112 |
# TODO: use a more granular timer |
#$cellular->send('AT^SPBG=38' . "\r\n"); |
|
sleep 1; |
|
113 |
|
|
114 |
#my $response = $cellular->input(); |
$cellular->response_read(); |
|
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; |
|
115 |
|
|
|
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; |
|
|
} |
|
116 |
|
|
117 |
|
$cellular->send('SDBR=90', 'SIEMENS'); |
118 |
|
$cellular->response_read(); |
119 |
|
|
120 |
1; |
1; |
121 |
__END__ |
__END__ |