$|=1; # No output buffering
+my $EMStext="";
+my @EMSudh;
+
#
# Arguments
my $opt_verbose;
"ring-send:s" => \$opt_ring_send,
"logo-group-send:s" => \$opt_logo_group_send,
"ems-force-variable" => \$opt_ems_force_variable,
- "ems-picture-send:s" => \$opt_ems_picture_send,
- "ems-animation-send:s" => \$opt_ems_animation_send,
- "ems-melody-file-send:s" => \$opt_ems_melody_file_send,
+ "ems-picture-send:s" => \&ems_picture_send,
+ "ems-animation-send:s" => \&ems_animation_send,
+ "ems-melody-file-send:s" => \&ems_melody_file_send,
"alcatel-name:s" => \$opt_alcatel_name,
"alcatel-picture-send:s" => \$opt_alcatel_picture_send,
"alcatel-animation-send:s" => \$opt_alcatel_animation_send,
$nbs->sendGroupGraphic_file($msisdn, $opt_logo_group_send);
}
- if ($opt_ems_picture_send) {
- my $bitmap = GSM::SMS::Bitmap->new($opt_ems_picture_send);
- $nbs->sendsms($msisdn, "", udh=>[ {
- "type"=>"ems_picture",
- TEXT_POSITION=>0,
- "bitmap"=>$bitmap,
- "force_variable"=>$opt_ems_force_variable,
- } ]);
- }
-
- if ($opt_ems_animation_send) {
- my @names=split /:/,$opt_ems_animation_send;
- die "Required exactly 4 colon (':') delimited filenames for --ems-animation-send" if 4 != @names;
- my @bitmaps=map { GSM::SMS::Bitmap->new($_); } @names;
- $nbs->sendsms($msisdn, "", udh=>[ {
- "type"=>"ems_animation",
- TEXT_POSITION=>0,
- "bitmaps"=>\@bitmaps,
- } ]);
- }
-
- if ($opt_ems_melody_file_send) {
- local (*F);
- open F, $opt_ems_melody_file_send;
- my $ems_melody_file_data = <F>;
- close F;
- warn "EMS iMelody file format not recognized, wrapping anyway"
- if $ems_melody_file_data!~/^BEGIN:IMELODY\r\n.*END:IMELODY\r\n$/s;
- $nbs->sendsms($msisdn, "", udh=>[ {
- "type"=>"ems_melody",
- TEXT_POSITION=>0,
- "textdata"=>$ems_melody_file_data,
- } ]);
+ if (@EMSudh || $EMStext ne "") {
+ $nbs->sendsms($msisdn, $EMStext, udh=>[ @EMSudh ]);
}
if ($opt_alcatel_picture_send) {
}
exit(0);
+
+sub ems_picture_send
+{
+my($keyword,$arg)=@_;
+
+ my $bitmap = GSM::SMS::Bitmap->new($arg);
+ push @EMSudh,{
+ "type"=>"ems_picture",
+ TEXT_POSITION=>length($EMStext),
+ "bitmap"=>$bitmap,
+ "force_variable"=>$opt_ems_force_variable,
+ };
+}
+
+sub ems_animation_send
+{
+my($keyword,$arg)=@_;
+
+ my @names=split /:/,$arg;
+ die "Required exactly 4 colon (':') delimited filenames for --ems-animation-send" if 4 != @names;
+ my @bitmaps=map { GSM::SMS::Bitmap->new($_); } @names;
+ my($width,$height)=GSM::SMS::NBS::Message::ems_animation_maxsize(\@bitmaps);
+ # Will we need some newlines?
+ if ($height>16) {
+ my $height_now;
+ for (my $y=0;$y<$height;$y+=$height_now) {
+ $height_now=($y+8>=$height ? 8 : 16);
+ # we don't do horizontal split here
+ push @EMSudh,{
+ "type"=>"ems_animation",
+ TEXT_POSITION=>length($EMStext),
+ "bitmaps"=>[ map({
+ GSM::SMS::Bitmap->new($_,0,$y,$width,$height_now);
+ } @bitmaps) ],
+ };
+ $EMStext.="\n" if $y+$height_now<$height;
+ }
+ return;
+ }
+ push @EMSudh,{
+ "type"=>"ems_animation",
+ TEXT_POSITION=>length($EMStext),
+ "bitmaps"=>\@bitmaps,
+ };
+}
+
+sub ems_melody_file_send
+{
+my($keyword,$arg)=@_;
+
+ local (*F);
+ open F, $opt_ems_melody_file_send;
+ my $ems_melody_file_data = <F>;
+ close F;
+ warn "EMS iMelody file format not recognized, wrapping anyway"
+ if $ems_melody_file_data!~/^BEGIN:IMELODY\r\n.*END:IMELODY\r\n$/s;
+ push @EMSudh,{
+ "type"=>"ems_melody",
+ TEXT_POSITION=>length($EMStext),
+ "textdata"=>$ems_melody_file_data,
+ };
+}