ril-at_tok.c分析

来源:互联网 发布:红旗linux怎么打开终端 编辑:程序博客网 时间:2024/05/17 06:27

局部变量初始化为任意值。
==============================================
1.作用:找到第一个:的位置
int at_tok_start(char **p_cur)
{
*p_cur = strchr(*p_cur, ':');
}
==============================================
2.作用:跳过空格
static void skipWhiteSpace(char **p_cur)
==============================================
3.作用:跳过冒号
static void skipNextComma(char **p_cur)
==============================================
4.作用:跳到下一个参数,返回当前参数。
static char * nextTok(char **p_cur)
{
 ret = strsep(p_cur, "\"");//分割字符
 strsep返回值为分割后的开始字符串,并将函数的第一个参数指针指向分割后的
 剩余字符串。它适用于分割关键字在两个字符串之间只严格出现一次的情况
}
==============================================
5.作用:解析下一个整数在AT响应命令,输出在P_OUT。
static int at_tok_nextint_base(char **p_cur, int *p_out, int base, int  uns)
参数:p_cur输入字符串    base多少进制   uns无符号。p_out为输出整形。

==================================================
6.
int at_tok_nextbool(char **p_cur, char *p_out)和at_tok_nextint差不多,只是结果只有0或者1.更安全。
int at_tok_hasmore(char **p_cur)//判断响应参数结束没有
int at_tok_nextstr(char **p_cur, char **p_out)//将分割的字符串给p_out 此函数和 at_tok_nextint相似
======================================================================
unsigned long strtoul(const char *nptr,char **endptr,int base);
将字符串转换成无符号长整型数(str,0,16)
unsigned long strtoul(const char *nptr,char **endptr,int base);
将字符串转换成长整型数(str,0,16)
endptr是一个传出参数,函数返回时指向后面未被识别的第一个字符。
例如char *pos; strtol("123abc", &pos, 10);,strtol返回123,pos指向字符串中的字母a


=============================================================
7.int at_tok_nextint(char **p_cur, int *p_out)
  int at_tok_nexthexint(char **p_cur, int *p_out)
Purpose:Parses the next base 16 integer in the AT response line and places it in *p_out
----------------------------------------------
具体分析:
 at_tok_nextint(&line, &response[0])
 {
  ret = nextTok(line);//分割line后给line,line分割前部分给ret。
  l = strtol(ret, &end, base);
  response[0]= (int)l;
 }

================================================================
8.对命令响应的处理:

requestRegistrationState
{
err = at_send_command_singleline(cmd, prefix, &p_response);//响应在p_response
line = p_response->p_intermediates->line;//line=+CREG: 2,5, 240090, 1039
err = at_tok_start(&line);//line=2,5, 240090, 1039
commas//commas=3逗号的个数
case 3: //line=2,5, 240090, 1039
       err = at_tok_nextint(&line, &skip);//2
    err = at_tok_nextint(&line, &response[0]);//5
       err = at_tok_nexthexint(&line, &response[1]); //240090      
       err = at_tok_nexthexint(&line, &response[2]);//1039

}
-----------------

原创粉丝点击