收发短信是oFono所支持的一项基本功能。用phonesim也可以模拟短信的收发。oFono本身不会保存短信,而是希望第三方plugin如sms history来把短信保存到sim卡或者SD卡上。
1. 启动oFono并power on modem。
2. ./ofono/test/receive-sms 用来监听是否有新的短信
3. 通过send-sms脚本可以发短信。比如
xxx@xxx:~/ofono/test$ ./send-sms 135xxxxxxxx "Hello World"
从oFono console log中可以看到短信发送的全过程。它会把短信encode成PDU格式,用AT+CMGS发送出去。你还可以设置短信delivery report来确认短信是否真正发送出去了。
ofonod[3372]: src/sms.c:sms_send_message() ref: 0, offset: 0
ofonod[3372]: src/sms.c:tx_queue_entry_new() pdu_len: 25, tpdu_len: 24
ofonod[3372]: Sending SMS on modem: 0x9009680
ofonod[3372]: InternalMessageId: 2
ofonod[3372]: To: 1xxxxxxxxxx:
ofonod[3372]: Local Time: 2010-09-17T10:23:12+0800
ofonod[3372]: Text: Hello World
ofonod[3372]: Pcui:< /r/n^MODE:3,3/r/n
...
ofonod[3372]: Pcui:> AT+CMGS=24/r
ofonod[3372]: Pcui:< /r/n>
ofonod[3372]: Pcui:&gt; 0031000B813165646315F50000A70BC8329BFD065DDF723619
ofonod[3372]: Pcui:< /r/n
ofonod[3372]: Pcui:&lt; /r/n^MODE:3,3/r/n
ofonod[3372]: Pcui:&lt; /r/n+CMGS: 5/r/n/r/nOK/r/n
ofonod[3372]: drivers/atmodem/sms.c:at_cmgs_cb() Got MR: 5
ofonod[3372]: src/sms.c:tx_finished() tx_finished
ofonod[3372]: SMS 2 submitted successfully
ofonod[3372]: Submission Time: 2010-09-17T10:23:53+0800
ofonod[3372]: Pcui:> AT+COPS=3,0/r
ofonod[3372]: Pcui:< /r/nOK/r/n
ofonod[3372]: Pcui:> AT+COPS?/r
ofonod[3372]: Pcui:< /r/n+COPS: 0,0,"CHINA  MOBILE",0/r/n/r/nOK/r/n
ofonod[3372]: drivers/atmodem/network-registration.c:cops_cb() cops_cb: CHINA  MOBILE, 460 00 0
ofonod[3372]: src/network.c:current_operator_callback() 0x9009da8, 0x900d438
ofonod[3372]: Pcui:&lt; /r/n^MODE:3,3/r/n
ofonod[3372]: Pcui:&lt; /r/n+CDS: 26/r/n0891683108200105F006040D91683165646315F5019071013284230190710132802300/r/n
ofonod[3372]: drivers/atmodem/sms.c:at_cds_notify() Got new Status-Report PDU via CDS: 0891683108200105F006040D91683165646315F5019071013284230190710132802300, 26
ofonod[3372]: src/sms.c:ofono_sms_status_notify() len 35 tpdu len 26
ofonod[3372]: src/sms.c:handle_sms_status_report()
4. 哈,我收到了来自oFono的Hello World,于是我从手机上回复了。oFono很快收到了我的回复。
ofonod[3372]: Pcui:&lt; /r/n+CMTI: "ME",0/r/n
ofonod[3372]: drivers/atmodem/sms.c:at_cmti_notify() Got a CMTI indication at ME, index: 0
ofonod[3372]: Pcui:> AT+CMGR=0/r
ofonod[3372]: Pcui:< /r/n+CMGR: 0,,34/r/n0891683108200105F0240D91683165646315F50000019071016265230F5474D8BD9EBB8E6F3A28FFAE8700/r/n/r/nOK/r/n
ofonod[3372]: drivers/atmodem/sms.c:at_cmgr_notify()
ofonod[3372]: drivers/atmodem/sms.c:at_cmgr_notify() Got PDU: 0891683108200105F0240D91683165646315F50000019071016265230F5474D8BD9EBB8E6F3A28FFAE8700, with len: 34
ofonod[3372]: src/sms.c:ofono_sms_deliver_notify() len 43 tpdu len 34
ofonod[3372]: src/sms.c:handle_deliver()
ofonod[3372]: src/sms.c:sms_dispatch()
ofonod[3372]: Incoming SMS on modem: 0x9009680
ofonod[3372]: InternalMessageId: 3
ofonod[3372]: From: +861xxxxxxxxxx
ofonod[3372]: Local Sent Time: 2010-09-17T10:26:56+0800
ofonod[3372]: Remote Sent Time: 2010-09-17T10:26:56+0800
ofonod[3372]: Text: Thanks.Got you!
ofonod[3372]: Pcui:> AT+CMGD=0/r
ofonod[3372]: Pcui:&lt; /r/nOK/r/n
xxx@xxx:~/ofono/test$ ./receive-sms
Thanks.Got you!
    LocalSentTime = 2010-09-17T10:26:56+0800
    SentTime = 2010-09-17T10:26:56+0800
    Sender = +861xxxxxxxxxx
怎么样,是不是很简单?