Device::Gsm:如何判断一组短信是否是一条消息?

发布于 2024-08-23 20:47:56 字数 950 浏览 4 评论 0原文

使用 Device::Gsm,我可以读取 umts-modem 上收到的短信。有时,由于一条短信长度的限制,一条短信会被分成两条或更多条短信。有没有办法查明一组短信是否是一条消息的一部分?例如,Wammu 会给我发送短信,这些短信属于一个文本。

#!/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";   
}  

已连接!

消息 N.0 文本 [消息 1 第 1 部分]

消息 N.1 文本 [消息 1 第 2 部分]

消息 N.2 文本 [消息 1 第 3 部分]

消息 N.3 文本[消息2]

消息 N.4 文本[消息3]

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]

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

甜`诱少女 2024-08-30 20:47:56

我认为没有办法直接使用 Device::Gsm 。但是,如果您在 PDU 模式下阅读消息(请参阅 https://metacpan.org/pod/ Device::Gsm#mode )然后您可以适当地解释标头以读出多部分标志。

[编辑添加:此参考是 SMS PDU 标头的精彩概述:
http://www.spallared.com/old_nokia/nokia/smspdu/smspdu。 htm]

I don't think there is a way with Device::Gsm directly. However if you read the message in PDU mode (see https://metacpan.org/pod/Device::Gsm#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 ]

静待花开 2024-08-30 20:47:56

这在大多数情况下有效,但并非总是有效。

#!/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"; 
}

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"; 
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文