首页 资讯 应用 高压 设计 行业 低压 电路图 关于

嵌入式

旗下栏目: PLC 嵌入式 单片机 DCS

AT+CSQ语法即GPRS模块信号格数与信号强度的关系

嵌入式 | 发布时间:2018-10-30 | 人气: | #评论# | 本文关键字:Android,GPRS,AT+CSQ
摘要:AT+CSQ语法 命令解释:检查网络信号强度 命令格式:AT+CSQCR 命令返回:+CSQ: **, ## 其中: **应在 0 到 31 之间(99表示无信号),数值越大表明信号质量越好; ##为误码 率,值在 0 到 99 之间。 否

AT+CSQ语法

命令解释:检查网络信号强度
命令格式:AT+CSQ<CR>
命令返回:+CSQ:  **, ##           其中:

    • **应在 0 到 31 之间(99表示无信号),数值越大表明信号质量越好;

    • ##为误码率,值在 0 到 99 之间。否则应检查天线或 SIM 卡是否正确安装

测试结果:AT+CSQ<CR>
                     +CSQ: 31, 99

计算公式:信号强度 = -113dBm + (rssi * 2)

通过AT+CSQ指令获取GPRS模块信号强度

如下图所示:

AT+CSQ

信号格数与信号强度的关系

手机格数与手机接收基站的信号强度有关,目前行业中并没有明确的标准,格数与信号强度关联均为厂商而定,iPhone 4信号强度与格数如下图:

诺基亚手机和iPhone 4信号强度与格数对比如下:

信号格数

接收电平强度

诺基亚

iPhone4

5格:

大于-85dBm

大于-91dBm

4:

-85dBm-90dBm

-91dBm-101dBm

3:

-90dBm-95dBm

-101dBm-103dBm

2:

-95dBm-100dBm

-103dBm-107dBm

1:

-100dBm-105dBm

-107dBm-113dBm

脱网:

小于-105 dBm

小于-113dBm

注:上表数据均为5格信号显示方式,如N97等7格信号原则与上述不同。

在这里,我采用了android系统上关于GSM模块信号格数与信号强度的对应关系,如下代码所示:

01public int getGsmLevel() {
02    int level;
03
04    // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
05    // asu = 0 (-113dB or less) is very weak
06    // signal, its better to show 0 bars to the user in such cases.
07    // asu = 99 is a special case, where the signal strength is unknown.
08    int asu = getGsmSignalStrength();
09
10    if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
11    else if (asu >= 12) level = SIGNAL_STRENGTH_GREAT;
12    else if (asu >= 8)  level = SIGNAL_STRENGTH_GOOD;
13    else if (asu >= 5)  level = SIGNAL_STRENGTH_MODERATE;
14    else level = SIGNAL_STRENGTH_POOR;
15
16    if (DBG) log("getGsmLevel=" + level);
17
18    return level;
19}

上面的asu即AT+CSQ指令返回的RSSI值。

参考文章:http://blog.csdn.net/garybook/article/details/17006609

如果是CDMA模块,应该可以参考下面的代码:

参考文章:http://www.2cto.com/kf/201306/218756.html

Android4.0的系统中,手机中显示信号强度格数的代码在

frameworks\base\telephony\java\android\telephony\SignalStrength.java

getLevel( )函数,该函数是主要用来获取信号的强度。

01public int getLevel() {
02        int level;
03
04        if (isGsm) {
05            level = getLteLevel();
06            if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
07                level = getGsmLevel();
08            }
09        else {
10            int cdmaLevel = getCdmaLevel();
11            int evdoLevel = getEvdoLevel();
12            if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
13                /* We don't know evdo, use cdma */
14                level = cdmaLevel;
15            else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
16                /* We don't know cdma, use evdo */
17                level = evdoLevel;
18            else {
19                /* We know both, use the lowest level */
20                //level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel; 
21                level = cdmaLevel > evdoLevel ? cdmaLevel : evdoLevel;
22            }
23        }
24        if (DBG) log("getLevel=" + level);
25        return level;
26    }
27
28public int getLevel() {
29        int level;
30
31        if (isGsm) {
32            level = getLteLevel();
33            if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
34                level = getGsmLevel();
35            }
36        else {
37            int cdmaLevel = getCdmaLevel();
38            int evdoLevel = getEvdoLevel();
39            if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
40                /* We don't know evdo, use cdma */
41                level = cdmaLevel;
42            else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
43                /* We don't know cdma, use evdo */
44                level = evdoLevel;
45            else {
46                /* We know both, use the lowest level */
47                //level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
48                level = cdmaLevel > evdoLevel ? cdmaLevel : evdoLevel;
49            }
50        }
51        if (DBG) log("getLevel=" + level);
52        return level;
53    }

getCdmaLevel( )获取CdmaLevel,同样也有getEvdoLevel( )函数,在上一个函数中,通过比较Evdo和Cdma的强度,来最终确定信号的显示强度,也就是我们在通知栏里看到的信号格数。

view source

01public int getCdmaLevel() {
02        final int cdmaDbm = getCdmaDbm();
03        final int cdmaEcio = getCdmaEcio();
04        int levelDbm;
05        int levelEcio;
06
07        if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT;
08        else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD;
09        else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE;
10        else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR;
11        else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
12
13        // Ec/Io are in dB*10 
14        if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
15        else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
16        else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
17        else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR;
18        else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
19
20        int level = (levelDbm < levelEcio) ? levelDbm : levelEcio;
21        if (DBG) log("getCdmaLevel=" + level + ",cdmaDbm=" + cdmaDbm + ",cdmaEcio=" +cdmaEcio);
22        return level;
23    }
24
25public int getCdmaLevel() {
26        final int cdmaDbm = getCdmaDbm();
27        final int cdmaEcio = getCdmaEcio();
28        int levelDbm;
29        int levelEcio;
30
31        if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT;
32        else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD;
33        else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE;
34        else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR;
35        else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
36
37        // Ec/Io are in dB*10
38        if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
39        else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
40        else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
41        else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR;
42        else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
43
44        int level = (levelDbm < levelEcio) ? levelDbm : levelEcio;
45        if (DBG) log("getCdmaLevel=" + level + ",cdmaDbm=" + cdmaDbm + ",cdmaEcio=" +cdmaEcio);
46        return level;
47    }


责任编辑:GPRS模块
首页 | 电气资讯 | 应用技术 | 高压电器 | 电气设计 | 行业应用 | 低压电器 | 电路图 | 关于我们 | 版权声明

Copyright 2017-2018 电气自动化网 版权所有 辽ICP备17010593号-1

电脑版 | 移动版 原创声明:本站大部分内容为原创,转载请注明电气自动化网转载;部分内容来源网络,如侵犯您的权益请发送邮件到[email protected]联系我们删除。