tags:

views:

41

answers:

2

Hello! With the Device::Gsm I can read the sms received on my umts-modem. Sometimes one message is divided in two or more sms because of the limitation of length of one sms. Is there a way to find out if a group of sms is a part of one message? Wammu for example shoes me sms that belong together as one text.

#!/usr/bin/perl  
use warnings; use strict;  
use Device::Gsm;  

my $modem = new Device::Gsm( port => '/dev/ttyUSB0' );  
if( $modem->connect() ) {  
    print "connected!\n";  
}   
else {  
    print "sorry, no connection with serial port!\n";  
}  

my @msg = $modem->messages;  
if( @msg ) {  
    my $n = 0;  
    for( @msg ) {  
    my $sms = $_;  
    next unless defined $sms;  
    print "\nMESSAGE N. $n\n";  
    print 'Text   [', $sms->text(), "]\n";  
    $n++;  
    }  
}  
else {   
    print "No message on SIM, or error during read!\n";   
}  

connected!

MESSAGE N. 0 Text [Message 1 Part 1]

MESSAGE N. 1 Text [Message 1 Part 2]

MESSAGE N. 2 Text [Message 1 Part 3]

MESSAGE N. 3 Text [Message 2 ]

MESSAGE N. 4 Text [Message 3]

+3  A: 

I don't think there is a way with Device::Gsm directly. However if you read the message in PDU mode (see http://search.cpan.org/~cosimo/Device-Gsm-1.54/Gsm.pm#mode() ) you can then interpret the header appropriately to read out the multipart flags.

[Edited to add: this reference is a great overview of the SMS PDU headers: http://www.spallared.com/old_nokia/nokia/smspdu/smspdu.htm ]

Vicky
I tried it with _MMS, but there was one multiple messages, where it didn't work.
sid_com
A: 

This works mostly, but not always.

#!/usr/bin/perl
use warnings; use strict; 
use 5.010;
binmode STDOUT, ':encoding(UTF-8)';
use Device::Gsm;

my $modem = new Device::Gsm( port => '/dev/ttyUSB0' );

if( $modem->connect() ) { 
    print "connected!\n"; 
} else { 
print "sorry, no connection with serial port!\n"; 
}

my @msg = $modem->messages( 'ME' );
if( @msg ) {
    print "You have messages!\n" ;
    my $n = 0;
    my $text;
    for my $sms ( @msg ) {
    next unless defined $sms;
    $text .= $sms->text;
    if ( $sms->{tokens}{PDUTYPE}{_MMS} ) {
        say "\nMESSAGE N. $n";
        say $text; 
        $text = '';
        $n++;
        <STDIN>;
    }
    }
} else { 
    print "No message or error during read!\n"; 
}
sid_com