RT-AX53U/sbin/read_sms

92 lines
1.6 KiB
Plaintext
Executable File

opengt
set com 115200n81
set senddelay 0.05
waitquiet 1 0.1
send "AT+CMGF=1^m"
gosub wait_ok
send "AT+CSMP=17,167^m"
gosub wait_ok
send "AT+CPMS=\"SM\",\"SM\",\"SM\"^m"
gosub wait_ok
send "AT+CMGL=\"ALL\"^m"
let i=0
open file "/tmp/read_sms"
:get_next
get 1 "^m" $s
fprint $s
let $a=$s
if len($a)>=3 let $b=$right($a,2)
#20060402##############################
if len($a)>=6 let $c=$right($a,5)
#print $a,"\n"
#print $b,"\n"
#print "c=[",$c,"]","\n"
if $c="ERROR" goto geterr
#20060402##############################
if $b="OK" goto exit
inc i
if i<45 goto get_next
if i>45 goto geterr
:exit
fprint "\n"
close file
#20060401###############################
#print "OK","\n"
system "rm -f /tmp/sms/read_script"
open file "/tmp/sms/read_script"
fprint "OK"
close file
#20060401###############################
gosub csca
exit 0
#20060402##############################
:geterr
#print "NONE","\n"
close file
system "rm -f /tmp/sms/read_script"
open file "/tmp/sms/read_script"
fprint "NONE"
close file
exit 0
#20060402##############################
:csca
let $t="none"
let $e="none"
let $c="none"
send "AT+CSCA?^m"
let i=0
:get_next2
get 2 "^m" $s
#print "s=",$s,"\n"
let $a=$s
if len($a)>=3 let $b=$right($a,2)
if len($a)>=5 let $e=$mid($a,1,6)
#print "b=",$b,"\n"
#print "e=",$e,"\n"
if $e="+CSCA:" let $c=$mid($a,8,len($a)-8) let $t=$c goto exit2
if $b="OK" goto exit2
inc i
if i<45 goto get_next2
:exit2
#print "t=",$t,"\n"
send "at+csca="+$t+"^m"
gosub wait_ok
#print "\n"
return
:wait_ok
let t=0
:get_again
get 1 " ^m" $s
let $a=$s
if len($a)>=3 let $b=$right($a,2)
if $b="OK" goto got_ok
else inc t
if t<45 goto get_again
else goto return
:got_ok
#print $s
:return
return