File: caller-id.pl

package info (click to toggle)
libdevice-modem-perl 1.59-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, bullseye, forky, sid, trixie
  • size: 452 kB
  • sloc: perl: 1,910; sh: 30; makefile: 2
file content (55 lines) | stat: -rw-r--r-- 1,412 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
#
# Demo of "Caller id" feature: detect who is calling us!
# Thanks to Marcelo Fernandez (mfernandez@lq.com.ar)
#
# $Id: caller-id.pl,v 1.1 2004-08-18 07:29:10 cosimo Exp $
#
use Device::Modem;

# Init modem
my $port = '/dev/ttyS0';
my $baud = 9600;
my $modem = Device::Modem->new( port => $port );

die "Can't connect to port $port!\n" unless $modem->connect( baudrate => $baud );
print "Connected to $port.\n\n";

# Init ATs
#$modem->atsend('AT S7=45 S0=0 L1 V1 X4 &c1 E1 Q0'.Device::Modem::CR); # 'Stolen' from minicom :P

# Set modem in autoanswer mode (to receive incoming calls)
# Doesn't work (it says "NO CARRIER") if I uncomment it
# $modem->atsend('ATA'.Device::Modem::CR);

# Enable Caller ID info
$modem->atsend('AT#CID=1'.Device::Modem::CR);

# Poll state of modem
my $received_call = 0;
my $number = '';

print "Waiting for call...\n";

while( ! $received_call ) {

	# Listen for data coming from modem
	my $cid_info = $modem->answer(undef, 3);  # 3 seconds timeout
	print "$cid_info\n" if ($cid_info);

	# If something received, take a look at it
	if( $cid_info =~ /NMBR\s*=\s*([\d\s]+)/ ) {

		# Ok, received! Number is in $1 var
		$number = $1;
		$received_call++;
		print "\nNumber $number IS CALLING!!\n";
	} elsif( $cid_info ) {
		# Received something else, we must investigate
	} else {
		# No data received. No call arrived.
	}
	# Repeat until done
}

$modem->disconnect();