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模块信号格数与信号强度的对应关系,如下代码所示:

public int getGsmLevel() {
    int level;

    // ASU ranges from 0 to 31 - TS 27.007 Sec 8.5
    // asu = 0 (-113dB or less) is very weak
    // signal, its better to show 0 bars to the user in such cases.
    // asu = 99 is a special case, where the signal strength is unknown.
    int asu = getGsmSignalStrength();

    if (asu <= 2 || asu == 99) level = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;
    else if (asu >= 12) level = SIGNAL_STRENGTH_GREAT;
    else if (asu >= 8)  level = SIGNAL_STRENGTH_GOOD;
    else if (asu >= 5)  level = SIGNAL_STRENGTH_MODERATE;
    else level = SIGNAL_STRENGTH_POOR;

    if (DBG) log("getGsmLevel=" + level);

    return level;
}

上面的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( )函数,该函数是主要用来获取信号的强度。

public int getLevel() { 
        int level; 
 
        if (isGsm) { 
            level = getLteLevel(); 
            if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { 
                level = getGsmLevel(); 
            } 
        } else { 
            int cdmaLevel = getCdmaLevel(); 
            int evdoLevel = getEvdoLevel(); 
            if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { 
                /* We don't know evdo, use cdma */ 
                level = cdmaLevel; 
            } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) { 
                /* We don't know cdma, use evdo */ 
                level = evdoLevel; 
            } else { 
                /* We know both, use the lowest level */ 
                //level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;  
                level = cdmaLevel > evdoLevel ? cdmaLevel : evdoLevel; 
            } 
        } 
        if (DBG) log("getLevel=" + level); 
        return level; 
    } 

public int getLevel() {
        int level;

        if (isGsm) {
            level = getLteLevel();
            if (level == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
                level = getGsmLevel();
            }
        } else {
            int cdmaLevel = getCdmaLevel();
            int evdoLevel = getEvdoLevel();
            if (evdoLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
                /* We don't know evdo, use cdma */
                level = cdmaLevel;
            } else if (cdmaLevel == SIGNAL_STRENGTH_NONE_OR_UNKNOWN) {
                /* We don't know cdma, use evdo */
                level = evdoLevel;
            } else {
                /* We know both, use the lowest level */
                //level = cdmaLevel < evdoLevel ? cdmaLevel : evdoLevel;
                level = cdmaLevel > evdoLevel ? cdmaLevel : evdoLevel;
            }
        }
        if (DBG) log("getLevel=" + level);
        return level;
    }

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

public int getCdmaLevel() { 
        final int cdmaDbm = getCdmaDbm(); 
        final int cdmaEcio = getCdmaEcio(); 
        int levelDbm; 
        int levelEcio; 
 
        if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT; 
        else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD; 
        else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE; 
        else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR; 
        else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 
 
        // Ec/Io are in dB*10  
        if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT; 
        else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD; 
        else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE; 
        else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR; 
        else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN; 
 
        int level = (levelDbm < levelEcio) ? levelDbm : levelEcio; 
        if (DBG) log("getCdmaLevel=" + level + ",cdmaDbm=" + cdmaDbm + ",cdmaEcio=" +cdmaEcio); 
        return level; 
    } 

public int getCdmaLevel() {
        final int cdmaDbm = getCdmaDbm();
        final int cdmaEcio = getCdmaEcio();
        int levelDbm;
        int levelEcio;

        if (cdmaDbm >= -75) levelDbm = SIGNAL_STRENGTH_GREAT;
        else if (cdmaDbm >= -85) levelDbm = SIGNAL_STRENGTH_GOOD;
        else if (cdmaDbm >= -95) levelDbm = SIGNAL_STRENGTH_MODERATE;
        else if (cdmaDbm >= -100) levelDbm = SIGNAL_STRENGTH_POOR;
        else levelDbm = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

        // Ec/Io are in dB*10
        if (cdmaEcio >= -90) levelEcio = SIGNAL_STRENGTH_GREAT;
        else if (cdmaEcio >= -110) levelEcio = SIGNAL_STRENGTH_GOOD;
        else if (cdmaEcio >= -130) levelEcio = SIGNAL_STRENGTH_MODERATE;
        else if (cdmaEcio >= -150) levelEcio = SIGNAL_STRENGTH_POOR;
        else levelEcio = SIGNAL_STRENGTH_NONE_OR_UNKNOWN;

        int level = (levelDbm < levelEcio) ? levelDbm : levelEcio;
        if (DBG) log("getCdmaLevel=" + level + ",cdmaDbm=" + cdmaDbm + ",cdmaEcio=" +cdmaEcio);
        return level;
    }
» 文章出处: reille博客—http://velep.com , 如果没有特别声明,文章均为reille博客原创作品
» 郑重声明: 原创作品未经允许不得转载,如需转载请联系reille#qq.com(#换成@)
分享到:

 Leave a Reply

(必须)

(我会替您保密的)(必须)

*

This site uses Akismet to reduce spam. Learn how your comment data is processed.

   
© 2012 velep.com | reille blog | 管理| 粤ICP备15065318号-2| 谷歌地图| 百度地图| Suffusion theme|Sayontan Sinha

无觅相关文章插件,快速提升流量