How to find out carrier signal strength programati

2019-01-23 09:44发布

Here is the code that I have used to find out carrier signal strength:

int getSignalStrength()
{
    void *libHandle = dlopen("/System/Library/Frameworks/CoreTelephony.framework/CoreTelephony", RTLD_LAZY);
    int (*CTGetSignalStrength)();
    CTGetSignalStrength = dlsym(libHandle, "CTGetSignalStrength");
    if( CTGetSignalStrength == NULL) NSLog(@"Could not find CTGetSignalStrength");
    int result = CTGetSignalStrength();
    dlclose(libHandle);
    return result;
}

It is giving me values between 60 to 100, but when I test the signal strength in device by calling to this *3001#12345#* number it showed me as -65. Below I have attached the screenshot. Is the value coming from getSignalStrength() accurate? Then why is it returning positive values always?

enter image description here

5条回答
我只想做你的唯一
2楼-- · 2019-01-23 10:07

My observation on CTGetSignalStrength() in CoreTelephony is that, it returns the RSSI(Received Signal Strength Indication) value of carrier's signal strength. My experiments with this returns values between the range 0 - 100, which I believe is the "percent signal strength" of the carrier according to this .

Also iOS does not measure signal strength in a linear manner according to this

I also noticed that, even when we have 5 bars in status bar, RSSI value may not be 100.

查看更多
看我几分像从前
3楼-- · 2019-01-23 10:10

getSignalStrength() is showing negated dB attenuation, e.g. -(-60) == 60. The call in is displaying it more conventionally as a measurement less than zero. Yes, these kinds of variations are typical. Even in strictly controlled conditions you can get +/- 20 decibels. One way you can fix it is to take a series of measurements over time, say every second, and keep a running list of the last 10 or so measurements. Then report the mean or median or some other statistic. In my experience this cuts down the variation a lot. You can also do standard deviation to provide a measure of reliability.

查看更多
beautiful°
4楼-- · 2019-01-23 10:11

getSignalStrength() provides the result in negative scale. The difference can be controlled using high pass filter.

You should gather the results of last 10 observations. At the time of adding new observation, take the average of last 10 observations. Multiply it by 0.1. Take the current reading and multiply it by 0.9. Add both. If total observations are greater than 10, remove the oldest observation for next calculation.

It will make your result more reliable and you can also handle sudden changes in the signal strength effectively.

查看更多
淡お忘
5楼-- · 2019-01-23 10:28

I would recommend reading up on decibel measure. The following link should help. How to Read Signal Strength

查看更多
放我归山
6楼-- · 2019-01-23 10:31

As for many signals getSignalStrength() should be used cojointly with a high-pass filter algorithm.

Also make sure to have an average measurement over some time (10-15 successive measurements). And it's normal that it gives negative result, dB signals for telephony are like that ;-)

查看更多
登录 后发表回答