| 1 |
joko |
1.1 |
#!/usr/bin/perl |
| 2 |
|
|
|
| 3 |
|
|
# $Id$ |
| 4 |
|
|
# $Log$ |
| 5 |
|
|
|
| 6 |
|
|
|
| 7 |
|
|
# 1. testing, status, introspection, command-groups, schema |
| 8 |
|
|
# 2. high-speed phonebook backup |
| 9 |
|
|
# 3. FollowMe: automagically detect connection, read IMEI |
| 10 |
|
|
# 4. protocol-declaration in xml (it's a "service"!) |
| 11 |
|
|
|
| 12 |
|
|
|
| 13 |
|
|
use strict; |
| 14 |
|
|
use warnings; |
| 15 |
|
|
|
| 16 |
|
|
use Win32::SerialPort; |
| 17 |
|
|
#use Unicode::String qw(ucs2 ucs4 latin1); |
| 18 |
|
|
|
| 19 |
|
|
use Data::Dumper; |
| 20 |
|
|
|
| 21 |
|
|
#require 'modules/me45/ME45.pm'; |
| 22 |
|
|
#my $me45 = ME45->new('COM1'); |
| 23 |
|
|
#$me45->get_vendor(); |
| 24 |
|
|
|
| 25 |
|
|
my $port = 'COM1'; |
| 26 |
|
|
my $quiet = 1; |
| 27 |
|
|
|
| 28 |
|
|
my $cellular = new Win32::SerialPort($port, $quiet); |
| 29 |
|
|
#$cellular->baudrate(57600); |
| 30 |
|
|
|
| 31 |
|
|
$cellular->baudrate(9600); |
| 32 |
|
|
$cellular->databits(8); |
| 33 |
|
|
$cellular->parity('none'); |
| 34 |
|
|
$cellular->stopbits(1); |
| 35 |
|
|
|
| 36 |
|
|
$cellular->error_msg(1); |
| 37 |
|
|
$cellular->user_msg(1); |
| 38 |
|
|
|
| 39 |
|
|
$cellular->debug(1); |
| 40 |
|
|
|
| 41 |
|
|
|
| 42 |
|
|
# toggle command echo mode on/off |
| 43 |
|
|
#$cellular->write('ATE0' . "\r\n"); |
| 44 |
|
|
#$cellular->write('ATE1' . "\r\n"); |
| 45 |
|
|
|
| 46 |
|
|
# send dummy AT |
| 47 |
|
|
#$cellular->write('AT' . "\r\n"); |
| 48 |
|
|
|
| 49 |
|
|
# query vendor/manufacturer info |
| 50 |
|
|
#$cellular->write('AT+CGMI' . "\r\n"); |
| 51 |
|
|
|
| 52 |
|
|
# model id code |
| 53 |
|
|
#$cellular->write('AT+CGMM' . "\r\n"); |
| 54 |
|
|
|
| 55 |
|
|
# gsm telephone version |
| 56 |
|
|
#$cellular->write('AT+CGMR' . "\r\n"); |
| 57 |
|
|
|
| 58 |
|
|
|
| 59 |
|
|
# query the cellulars clock |
| 60 |
|
|
#$cellular->write('AT+CCLK?' . "\r\n"); |
| 61 |
|
|
#$cellular->write('AT+CCLK?' . "\r\n"); |
| 62 |
|
|
|
| 63 |
|
|
# query the serial number (IMEI) |
| 64 |
|
|
#$cellular->write('AT+CGSN' . "\r\n"); |
| 65 |
|
|
#$cellular->write('AT+GSN' . "\r\n"); |
| 66 |
|
|
|
| 67 |
|
|
# phone status |
| 68 |
|
|
#$cellular->write('AT+CPAS' . "\r\n"); |
| 69 |
|
|
|
| 70 |
|
|
# price per unit |
| 71 |
|
|
#$cellular->write('AT+CPUC?' . "\r\n"); |
| 72 |
|
|
|
| 73 |
|
|
# query capabilities |
| 74 |
|
|
#$cellular->write('AT+GCAP' . "\r\n"); |
| 75 |
|
|
|
| 76 |
|
|
# sms stuff |
| 77 |
|
|
#$cellular->write('AT^SMGL=4' . "\r\n"); |
| 78 |
|
|
#$cellular->write('AT^SMGR=3' . "\r\n"); |
| 79 |
|
|
|
| 80 |
|
|
# off |
| 81 |
|
|
#$cellular->write('AT^SMSO' . "\r\n"); |
| 82 |
|
|
|
| 83 |
|
|
# database access |
| 84 |
|
|
#$cellular->write('AT^SDBR=90' . "\r\n"); |
| 85 |
|
|
|
| 86 |
|
|
# output signal quality |
| 87 |
|
|
#$cellular->write('AT+CSQ' . "\r\n"); |
| 88 |
|
|
|
| 89 |
|
|
# telephone book access |
| 90 |
|
|
#$cellular->write('AT+CPBR=93' . "\r\n"); |
| 91 |
|
|
|
| 92 |
|
|
# play signal tone |
| 93 |
|
|
#$cellular->write('AT^SPST=0,1' . "\r\n"); |
| 94 |
|
|
|
| 95 |
|
|
# use GSM charset |
| 96 |
|
|
#$cellular->write('AT+CSCS=GSM' . "\r\n"); |
| 97 |
|
|
#$cellular->write('AT+CSCS=UCS2' . "\r\n"); |
| 98 |
|
|
|
| 99 |
|
|
# organizer database (vcalendar entries in hex) |
| 100 |
|
|
# > AT^SBNW=? |
| 101 |
|
|
# ^SBNW: ("bmp",(0-3)),("mid",(0-5)),("vcf",(0-500)),("vcs",(0-50)),("t9d",(0)),("bmx",(4)) |
| 102 |
|
|
#$cellular->write('AT^SBNW=?' . "\r\n"); |
| 103 |
|
|
#$cellular->write('AT^SBNR="vcs",3' . "\r\n"); |
| 104 |
|
|
#$cellular->write('AT^SBNR="bmp",2' . "\r\n"); |
| 105 |
|
|
#$cellular->write('AT^SBNR="vcf",55' . "\r\n"); |
| 106 |
|
|
$cellular->write('AT^SBNR="vcf",38' . "\r\n"); |
| 107 |
|
|
#$cellular->write('AT^SBNR="vcf",124' . "\r\n"); |
| 108 |
|
|
#$cellular->write('AT^SBNR="vcf",125' . "\r\n"); |
| 109 |
|
|
|
| 110 |
|
|
# phonebook -search and -lookup ... |
| 111 |
|
|
# ... by letter |
| 112 |
|
|
#$cellular->write('AT^SPBC=K' . "\r\n"); |
| 113 |
|
|
#$cellular->write('AT^SPBC=K' . "\r\n"); |
| 114 |
|
|
# ... by index |
| 115 |
|
|
#$cellular->write('AT^SPBG=38' . "\r\n"); |
| 116 |
|
|
|
| 117 |
|
|
# select different telephone book |
| 118 |
|
|
#$cellular->write('AT^SPBS=?' . "\r\n"); |
| 119 |
|
|
#$cellular->write('AT^SPBS=MC' . "\r\n"); |
| 120 |
|
|
#$cellular->write('AT^SPBG=?' . "\r\n"); |
| 121 |
|
|
#$cellular->write('AT^SPBC=?' . "\r\n"); |
| 122 |
|
|
|
| 123 |
|
|
#$cellular->write('AT^SPBS=CS' . "\r\n"); |
| 124 |
|
|
#$cellular->write('AT^SPBG=38' . "\r\n"); |
| 125 |
|
|
|
| 126 |
|
|
|
| 127 |
|
|
# sleep a bit |
| 128 |
|
|
# TODO: use a more granular timer |
| 129 |
|
|
sleep 1; |
| 130 |
|
|
|
| 131 |
|
|
#my $response = $cellular->input(); |
| 132 |
|
|
my $res_count; |
| 133 |
|
|
my $res_payload; |
| 134 |
|
|
($res_count, $res_payload) = $cellular->read(500); |
| 135 |
|
|
print "> ", $res_payload, "\n"; |
| 136 |
|
|
|
| 137 |
|
|
if (my $data = bfb::extract($res_payload)) { |
| 138 |
|
|
print "-" x 30, "\n"; |
| 139 |
|
|
print $data, "\n"; |
| 140 |
|
|
print "-" x 30, "\n"; |
| 141 |
|
|
} |
| 142 |
|
|
|
| 143 |
|
|
$cellular->close(); |
| 144 |
|
|
undef $cellular; |
| 145 |
|
|
|
| 146 |
|
|
|
| 147 |
|
|
|
| 148 |
|
|
package bfb; |
| 149 |
|
|
|
| 150 |
|
|
use Data::Dumper; |
| 151 |
|
|
|
| 152 |
|
|
sub decode { |
| 153 |
|
|
my $data = shift; |
| 154 |
|
|
my @buf; |
| 155 |
|
|
for (my $i = 0; $i <= length($data); $i = $i + 2) { |
| 156 |
|
|
my $nybble = substr($data, $i, 2); |
| 157 |
|
|
push @buf, chr(hex($nybble)); |
| 158 |
|
|
} |
| 159 |
|
|
return join('', @buf); |
| 160 |
|
|
} |
| 161 |
|
|
|
| 162 |
|
|
sub extract { |
| 163 |
|
|
my $data = shift; |
| 164 |
|
|
my @parts = split("\r\n", $data); |
| 165 |
|
|
|
| 166 |
|
|
#print Dumper(@parts); |
| 167 |
|
|
#exit; |
| 168 |
|
|
|
| 169 |
|
|
my $res = ''; |
| 170 |
|
|
|
| 171 |
|
|
BLOCK: |
| 172 |
|
|
|
| 173 |
|
|
# ignore first two lines of each block |
| 174 |
|
|
shift @parts; |
| 175 |
|
|
shift @parts; |
| 176 |
|
|
|
| 177 |
|
|
if (my $payload = shift @parts) { |
| 178 |
|
|
$res .= $payload; |
| 179 |
|
|
} |
| 180 |
|
|
|
| 181 |
|
|
goto BLOCK if @parts; |
| 182 |
|
|
|
| 183 |
|
|
my $res_dec = bfb::decode($res); |
| 184 |
|
|
|
| 185 |
|
|
return $res_dec; |
| 186 |
|
|
} |
| 187 |
|
|
|
| 188 |
|
|
|
| 189 |
|
|
1; |
| 190 |
|
|
__END__ |