Device::Gsm:如何判断一组短信是否是一条消息?
使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为没有办法直接使用 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 ]
这在大多数情况下有效,但并非总是有效。
This works mostly, but not always.