手机启动方式:
1>USB连接到手机;
当手机通过USB连接到PC端的时候,因为手机显示充电图标,所以手机操作系统已经启动了.只是当前状态属于深度睡眠状态.
2>长按开机键;
通常用户都是通过这个方式进行开关机操作.用户长按开机键,那么系统开始上电启动.后面关于这部分会重点展开描述.
3>闹钟开机;
关机后闹钟响起了,而且还可以提示用户,让用户选择是否开机.那么这个时候必然操作系统是处于自动状态.为什么?因为当用户插入电池的时候,操作系统已经启动了,只是处于深度休眠状态,这个系统的功耗是最低的.
4>定时开机;
让手机定时关机很容易理解,只需要执行关机指令就可以了;但是让手机处于关机状态下,为什么到了指定的时间还可以自动开机?传统的思维:比如,PC关机后内存中的所有数据都会丢失,系统的时间是保存在BIOS中的,但是手机,尤其是feature phone上没有专门的BIOS芯片,那手机在关机后是如何保存当前时间的?其实从用户角度所看到的关机,只是让操作系统关闭掉了大部分模块而已.USB模块和系统时钟模块等都是处于活动状态.所以当重新开机的时候,系统的时间能够显示正确.[拔电池并且等待一会,这样的操作不在描述之内].
mmi 部分的代码:
--------------------------
void mmi_main_entry(void)
{
mmi_init_procedure();
/* power on cause handling */
/* 1. Long press power key */
/* 2. Charge insert */
/* 3. RTC Alarm */
mmi_main_poweron_cause_handler(mmiSignalBuf, cause);
/* system initialization */
/* initialize all variables and AT command */
mmi_system_module_initialize();
while(TRUE)
{
if( signal )
{
/* All the signal will be handler at here */
/* mmi handler the signal of ACI/Keypad/RTC/vibrate/handset and so on */
mmi_handler_signal(signal_ig,signal_body);
}
}
}
第一部分,MMI初始化,mmi_init_procedure().
从函数名称上就可以看出来,这部分主要是为了初始化MMI层的数据的,如:
a.初始化SIM卡,PIN, PUK码相关的变量,PIN,PUK码的密码,以及输入密码的计数器,以及SIM卡是否加锁等.
初始化手机默认语言,手机信号[RSSI,Received Signal Strength Indicator]等.
b.设置手机功能:
/* AT+CFUN=1,表示手机所有功能都打开 */
mmi_sys_send_at_command("AT+CFUN=1",9,AT_PLUS_CFUN, SIM1)
如果AT+CFUN=0的话,表示打开手机的最小功能[类似飞行模式],但是这个具体和OEM厂商有关系,不见得每个OEM厂商都会严格遵守3GPP的规范.
c.输入法初始化:
mmi_ime_initialize();
d.设置背光灯,LED参数,启动背光灯,
e.初始化电话本,短信,通话记录链表;
f.初始化闹钟;
第二部分,处理开机事件.根据不同的开始模式初始化不同的数据.
a.长按开机键开机;
b.充电模式下开机;
c.闹钟模式下开机;
第三部分,系统初始化
a.设置命令的回显模式:
/* Set command echo mode off
ATE[<val>]
<val>: integer type
0 received character will not be echoed to TE
1 received character will be echoed to TE; default setting
*/
mmi_sys_send_at_cmd("ATE0",4,AT_E, SIM1);
b.设置移动设备事件报告
设置代码如下,mode设置为3,ind设置为2,其它参数默认为0,这样系统[键盘\充电\短信\短信存储\电话本\SIM是否插入\漫游等]有任何改变的时候都会主动通知到MMI层.
/* Set +CIEV indication on
Mobile Equipment Event Reporting
+CMER=[<mode>[,<keyp>[,<disp>[,<ind>[,<bfr>]]]]]
<mode>: integer type
0 buffer unsolicited result codes in MS; if MS result code buffer is full,
the oldest one is discarded
3 forward unsolicited result codes directly to TE; TE-MS link shall use
specific in-band technique to embed result codes and data
when MS is is on-line data mode
<keyp>: integer type
0 no keypad event reporting
<disp>: integer type
0 no display event reporting
<ind>: integer type
0 no display event reporting
2 indicator event reporting will be sent when there is any defined event occurring
*/
mmi_sys_send_at_cmd("AT+CMER=3,,,2",13,AT_PLUS_CMER, SIM1);
通常通知MMI的方式:
ACI层发送包含对应信息的signal的AT指令到MMI层.
比如:
+CIEV: 9,1 #SIM is inserted
MMI接收到AT+CIEV: 9,1 指令后,就知道设备上已经插入了SIM卡.
b.设置字符集
通知TA: TE使用的字符集为HEX. 确保TA能够正确的转换MT和TE的字符串.
/* Set character set as "HEX"
Select TE Character Set
+CSCS=[<chset>]
<chset>:
¨GSM〃 GSM default alphabet
¨HEX〃 Character strings consist only of hexadecimal numbers from 00 to FF;
e.g. ¨032FE6〃 equals three 8-bit characters with decimal values 3, 47
and 230;no conversions to the original ME character set shall be done.
¨IRA〃 International reference alphabet
¨PCCP437〃 PC character set Code Page 437
¨PCDN〃 PC Danish/Norwegian character set
¨8859-1〃 ISO 8859 Latin 1 character set
¨UCS2〃 16-bit universal multiple-octet coded character set; UCS2 character strings
are converted to hexadecimal numbers from 0000 to FFFF;
e.g. ¨004100620063〃 equals three 16-bit characters with decimal values 65,98 and 99.
*/
mmi_sys_send_at_cmd("AT+CSCS=\"HEX\"",13,AT_PLUS_CSCS,SIM1);
c.设置短信首选存储方式:
实现过程如下:
/* <mem1>
Memory from which messages are read and deleted
SM SIM message storage
ME Mobile Equipment message storage
MT combination of "ME" and "SM" storages
<mem2> Messages will be written and sent to this memory storage:
SM SIM message storage
ME Mobile Equipment message storage
MT combination of "ME" and "SM" storages
<mem3> Memory in which received messages are preferred to be stored, if
routing to TE is not set (see AT+CNMI command with parameter<mt>=2) */
mmi_sys_send_at_cmd("AT+CPMS=\"SM\",\"SM\",\"ME\",13,AT_PLUS_CPMS,SIM1);
短消息类(class)的概念:根据指定储存的位置,短消息分为class 0 – 3四个类。也可以不指定类(no class),由ME按默认设置进行处理,存储到内存或者SIM卡中。在TPDU的TP-DCS字节中,当bit7-bit4为00x1, 01x1, 1111时,bit1-bit0指出消息所属类:
00 – class 0:只显示,不储存
01 – class 1:储存在ME内存中
02 – class 2:储存在SIM卡中
03 – class 3:直接传输到TE
当TE 处于在用状态时(如:DTR 信号处于“ON”状态),使用设置命令,可设置新消息如何从网络侧发送到TE。若TE 处于待用状态(如:DTR[数据终端就绪] 信号处于“OFF”状态),消息接收流程应该按照GSM 03.38 的规定。
/* +CNMI=[<mode>[,<mt>[,<bm>[,<ds>[,<bfr>]]]]]
<mode>:控制通知TE的方式
2 当数据链路被占用时,先缓冲起来,等空闲的时候再通知TE
<mt>:设置短消息存储和通知TE的内容
1 把接收到消息保存到默认位置,并且用: +CMTI: <mem>,<index> 通知TE
<bm>:设置小区广播
2 新的广播消息到达,直接用下面的方式通知TE:
+CBM: <length><CR><LF><pdu> (PDU mode enabled) or
+CBM: <sn>,<mid>,<dcs>,<page>,<pages><CR><LF><data> (Text mode enabled)
<ds>:短信状态报告
1 返回下面的指令通知TE短信状态报告:
+CDS: <length><CR><LF><pdu> (PDU mode enabled) or
+CDS: <fo>,<mr>,[<ra>],[<tora>],<scts>,<dt>,<st> (text mode enabled)
<bfr>:
0 TA buffer of unsolicited result codes defined within this command is flushed to the TE when <mode> 1...3 is entered (OK response shall be given before flushing the codes).
*/
mmi_sys_send_at_cmd((n8*)"AT+CNMI=2,1,2,1,0",17,AT_PLUS_CNMI,SIM1);
e. 打开ME的错误报告
/*
Report Mobile Equipment Error
+CMEE=[<n>]
<n>:
0 disable +CME ERROR: <err> result code and use ERROR instead
1 enable +CME ERROR: <err> result code and use numeric <err> values (refer next subclause)
2 enable +CME ERROR: <err> result code and use verbose <err> values (refer next subclause)
*/
mmi_sys_send_at_cmd("AT+CMEE=1",9,AT_PLUS_CMEE,SIM1);
d.查询IMEI[International Mobile Equipment Identity]
mmi_sys_send_at_cmd("AT+CGSN",7,AT_PLUS_CGSN,SIM1);
返回结果举例:
350390-01-005066-5-01
350390: TAC (Type Approval Code)
01: FAC (Final Assembly Code)
005066: SNR (Serial Number)
5: CD (Check Digit)
01: SVN of IMEISV
第四部分,做完了前面三部分的事情,那么MMI就开始通过轮训的方式守株待兔等待keypad\SIM\handset\SMS\Phonebook等模块发过来的signal,然后根据不同的信号内容采取不同的处理.
术语解释:
MS, Mobile Station,comprises all user equipment and software needed for communication with a mobile network, the mobile station consists of four components:
MT, Mobile Terminated,简单来说MT提供了访问网络的物理连接能力[GSM+GPRS].
TE, Terminal equipment,简单来说笔记本通过USB连接到手机,然后访问网络,那么这个时候笔记本就是TE,主要完成端到端的应用.
TA,Terminal Adapter, In ISDN terminology, a terminal adapter or TA is a device that connects a terminal (computer) to the ISDN network.
SIM, Subscriber Identify Module.
PS:
MT和TE可以是不同设备也可以是同一个设备,比如手机可以直接访问网络.在飞行模式打开的情况手机就只能是一个TE.
TPDU,Transport Protocol Data Unit
TP- DCS,Transport Protocol Data Coding Scheme