Preliminary version of EMS and Alcatel proprietary format implemented
[gsmperl.git] / GSM / examples / commandline / gsmcmd
1 #! /usr/bin/perl
2
3 use strict;
4 use warnings;
5
6 #
7 # Load some modules
8 use GSM::SMS::Config;
9 use GSM::SMS::NBS;
10 use GSM::SMS::Bitmap;
11 use GSM::SMS::NBS::Message;
12 use Getopt::Long;
13 require GSM::SMS::NBS::Alcatel;
14
15 $|=1;     # No output buffering
16
17
18 #
19 # Arguments
20 my $opt_verbose;
21 my $opt_transport;
22 my $opt_ring_send;
23 my $opt_logo_group_send;
24 my $opt_ems_picture_send;
25 my $opt_ems_animation_send;
26 my $opt_alcatel_name;
27 my $opt_alcatel_picture_send;
28 my $opt_alcatel_animation_send;
29 GetOptions( 
30         "v|verbose"                => \$opt_verbose,
31         "transport:s"              => \$opt_transport,
32         "ring-send:s"              => \$opt_ring_send,
33         "logo-group-send:s"        => \$opt_logo_group_send,
34         "ems-picture-send:s"       => \$opt_ems_picture_send,
35         "ems-animation-send:s"     => \$opt_ems_animation_send,
36         "alcatel-name:s"           => \$opt_alcatel_name,
37         "alcatel-picture-send:s"   => \$opt_alcatel_picture_send,
38         "alcatel-animation-send:s" => \$opt_alcatel_animation_send,
39 );
40
41 unless ( @ARGV ) {
42         print <<EOT;
43 Usage: $0 [--verbose] [--transport=<transport.conf>]
44        [--ring-send=<rtttl file>]
45        [--logo-group-send=<image file>]
46        [--ems-picture-send=<image file>]
47        [--ems-animation-send=<image file>]
48        [--alcatel-name=<resource name>]
49        [--alcatel-picture-send=<image file>]
50        [--alcatel-animation-send=<image file>]
51        <phone numbers>...
52 EOT
53         exit(1);
54 }
55
56 #
57 # Initialize
58 my $nbs = GSM::SMS::NBS->new( $opt_transport ? $opt_transport : "/dev/null" );
59
60 my $msisdn;
61 my $message;
62 my $timestamp;
63 my $transportname;
64 my $port;
65
66 undef $/; # Read files at once, NEVER set it before as at least NBS->new() needs line-reading!
67
68 for $msisdn (@ARGV) {
69
70         if ($opt_ring_send) {
71                 local (*F);
72                 open F, $opt_ring_send;
73                 my $rtttl_string = <F>;
74                 close F;
75                 $nbs->sendRTTTL($msisdn, $rtttl_string);
76         }
77
78         if ($opt_logo_group_send) {
79                 $nbs->sendGroupGraphic_file($msisdn, $opt_logo_group_send);
80         }
81
82         if ($opt_ems_picture_send) {
83                 my $bitmap = GSM::SMS::Bitmap->new($opt_ems_picture_send);
84                 $nbs->sendsms($msisdn, "", udh=>[ { "type"=>"ems_picture", TEXT_POSITION=>0, "bitmap"=>$bitmap } ]);
85         }
86
87         if ($opt_ems_animation_send) {
88                 my @names=split /:/,$opt_ems_animation_send;
89                 die "Required exactly 4 colon (':') delimited filenames for --ems-animation-send" if 4 != @names;
90                 my @bitmaps=map { GSM::SMS::Bitmap->new($_); } @names;
91                 $nbs->sendsms($msisdn, "", udh=>[ { "type"=>"ems_animation", TEXT_POSITION=>0, "bitmaps"=>\@bitmaps } ]);
92         }
93
94         if ($opt_alcatel_picture_send) {
95                 my $bitmap = GSM::SMS::Bitmap->new($opt_alcatel_picture_send);
96                 my ($msg, $udh) = GSM::SMS::NBS::Alcatel->alcatel_picture($bitmap);
97                 $udh->[0]{"name"}=$opt_alcatel_name if defined $opt_alcatel_name;
98                 $nbs->sendsms($msisdn, $msg, udh=>$udh);
99         }
100
101         if ($opt_alcatel_animation_send) {
102                 my @names=split /:/,$opt_alcatel_animation_send;
103                 my %imgmap=();
104                 my @list=map {
105                                 if (/^\d+$/) {
106                                         $_;
107                                 } else {
108                                         $imgmap{$_}=GSM::SMS::Bitmap->new($_) if (!exists $imgmap{$_});
109                                         $imgmap{$_};
110                                 }
111                 } @names;
112                 my ($msg, $udh) = GSM::SMS::NBS::Alcatel->alcatel_animation(@list);
113                 $udh->[0]{"name"}=$opt_alcatel_name if defined $opt_alcatel_name;
114                 $nbs->sendsms($msisdn, $msg, udh=>$udh);
115         }
116 }
117
118 exit(0);