3
我正在嘗試將一些錯誤檢測添加到用於從我們的監控系統發送SMS消息的腳本中。大多數情況下,它像魅力一樣工作,但在極少數情況下,它會停止發送消息,我們不知道爲什麼。3G調制解調器中的錯誤檢測
我們還沒有能夠重現錯誤,所以我想知道如果有人有過類似的問題。下面是發送消息的代碼,下面有一個我可能能夠捕獲錯誤的想法。
這裏是發送消息的代碼:
sub sendsms {
my ($number,$msg) = @_;
my $store = undef;
my $status = undef;
$msg =~ tr/\\[\]_'^~\{\}\|/\/\(\)\-"??\(\)!/; # \ -> /, [ -> (, ] ->), ...., strippa út [ ] _ '^~ { } | \
$msg =~ tr/\xe1\xe9\xed\xf3\xfa\xfd\xf0\xfe\xe6\xf6\xc1\xc9\xcd\xd3\xda\xdd\xd0\xde\xc6\xd6/aeiouydtaoAEIOUYDTAO/;
for (my $i = 0; $i < length($msg); $i++) {
substr($msg,$i,1) = '_' if (ord(substr($msg,$i,1)) < 0x20 || ord(substr($msg,$i,1)) > 0x7f);
}
my $s = substr($msg,0,$maxlen);
RETRY: for (my $t = 0; $t < 5; $t++) {
eval {
put('AT+CMGD='.($next_store+1), 'OK');
put('AT+CSCA="'.$sca.'",145', 'OK');
put('AT+CMGF=1', 'OK');
put('AT+CMGW="'.$number.'",145', '>');
put($s, '>');
my $a = put("\x{1a}", undef);
print "a = '$a'\n" if ($verbose);
if ($a =~ /\+CMGW: ([0-9]*)/) {
$store = $1;
last RETRY;
}
};
if ([email protected]) {
print "ERROR: attempt $t: [email protected]\n";
}
sleep 2*($t+1);
}
if (defined $store) {
print "Message store $store\n" if ($verbose);
put('AT+CMSS='.$store.',"'.$number.'",145',undef);
$next_store = (($store - 1) + 1) % $stores;
}
else {
die "Message not stored";
}
}
認沽功能:
sub put {
my ($cmd,$expect) = @_;
print "Sending command '$cmd' expecting '$expect'\n" if ($verbose);
$modem->atsend($cmd."\r\n") || die "FAILED send\n";
my $a = $modem->answer();
die "Failed '$cmd' expected '$expect' got '$a'\n" if (defined $expect && !($a =~ /$expect/));
return $a;
}
就像我剛纔說這個作品的99%的時間。該錯誤似乎是消息被寫入商店但從未發送。
我的想法:
eval {'$status = AT+CPAS'};
if (defined $status and ($status == '+CPAS: 1' or $status == '+CPAS: 2')){
print "Modem returned an error status: ".$status;
flush_stores();
sendsms('+xxxxxxxxxx', 'There is an error in the 3G modem');
}
沖洗功能:
sub flush_stores {
for (my $i = 0; $i < $stores; $i++) {
put('AT+CMGD='.($i+1), 'OK');
}
}
將這項工作?
如果不是,將會怎樣?
Gísli
@daxim謝謝,我忘了put函數,將它添加到sendingms函數的下面 – Gisli