--ems-melody-file-send wrapper implemented
[gsmperl.git] / GSM / SMS / NBS / Message.pm
index 4aa132b..ed6fbe3 100644 (file)
@@ -19,6 +19,7 @@ use constant USERDATA_LENGTH    => 140;
 use constant DECONCAT_TOTAL     => "_deconcat_total";  # internal: undef=>try single message, *=>try & messages
 use constant TEXT_POSITION      => "text_position";    # numeric position in $payload, UDH IE will be present only once
 
+use constant IEI_IMELODY          => 0x0C;  #IEI: User Defined Sound (iMelody max 128 bytes)
 use constant IEI_ANIMATION_LARGE  => 0x0E;  #IEI: EMS large animation (16x16 x4 = 128 bytes)
 use constant IEI_ANIMATION_SMALL  => 0x0F;  #IEI: EMS small animation ( 8x 8 x4 =  32 bytes)
 use constant IEI_PICTURE_LARGE    => 0x10;  #IEI: EMS large    picture (32x32 = 128 bytes)
@@ -94,6 +95,10 @@ sub _ie_concat8 {
        );
 }
 
+# Use $args{"force_variable"} to force type IEI_PICTURE_VARIABLE
+# It needs to be used for compatibility with Alcatel 311 (firmware 101.01)
+#  - reported/tested by Radek Kadner <radek.kadner@atspraha.cz>
+
 sub _ie_ems_picture {
        my ($self, %args) = @_;
        my $bitmap = $args{"bitmap"};  # GSM::SMS::Bitmap instance
@@ -105,6 +110,7 @@ sub _ie_ems_picture {
           if ($width == 16 && $height == 16) { $iei = IEI_PICTURE_SMALL   ; }
        elsif ($width == 32 && $height == 32) { $iei = IEI_PICTURE_LARGE   ; }
        else                                  { $iei = IEI_PICTURE_VARIABLE; }
+       $iei = IEI_PICTURE_VARIABLE if $args{"force_variable"};
 
        return $self->_iebuilder($iei,
                        $args{TEXT_POSITION}, # position in the SMS
@@ -148,13 +154,22 @@ sub _ie_ems_animation {
        );
 }
 
+sub _ie_ems_melody {
+       my ($self, %args) = @_;
+       
+       return $self->_iebuilder(IEI_IMELODY,
+                       $args{TEXT_POSITION}, # position in the SMS
+                       unpack("C*",$args{"textdata"}),
+       );
+}
+
 sub _ie_alcatel {
        my ($self, %args) = @_;
 
        return $self->_iebuilder(IEI_ALCATEL,
                        (!defined($args{"name"}) ? (0x00) :  # bit 7=0 (use GSM charset)
                                        (length($args{"name"}), unpack("C*",
-                                                       encode_payload(0xF5, GSM::SMS::PDU->inversetranslate($args{"name"}))))  # 0xF5 DCS=any 8bit
+                                                       encode_payload(0xF1, GSM::SMS::PDU->inversetranslate($args{"name"}))))  # 0xF1 DCS=any 7bit
                                        ),
                        (!!$args{"ems_compat"} << 7)  # bit 7=EMS compatibility
                                        |($args{"alcatel_type"} & 0x07),  # bits 0..2=Alcatel message type
@@ -221,8 +236,12 @@ sub _store_try {
                my $payload_now="";          # text  from $payload       placed in the current SMS part
                while (1) {
                        if (@udhpositioned && $udhpositioned[0]{TEXT_POSITION} <= $position) { # "<=" should be "=="
-                               last if USERDATA_LENGTH < length($self->_udh_build(@udhstatic,@udhpositioned_now,$udhpositioned[0]))
-                                               +nail_payload_len($dcs,length($payload_now));
+                               if (USERDATA_LENGTH < length($self->_udh_build(@udhstatic,@udhpositioned_now,$udhpositioned[0]))
+                                               +nail_payload_len($dcs,length($payload_now))) {
+                                       return "UDH IE (User Data Header Information Element) too long to fit in one SMS fragment"
+                                                       if $payload_now eq "";
+                                       last;
+                                       }
 
                                my %udhei=%{shift @udhpositioned};  # copy it to local state - we will be modifying it
                                # we subtract the absolute position base of current SMS part: