GPRS signal strength

L

leibnizster

Hello,

| am involved in a project and we have to get the signal strength of
the current GPRS connection. I heard about using ril.h and TAPI. Which
one should we use and how? Any advice would be greatly appreciated.


Thanks
 
M

Matt

Hello,

You are going to need to use TAPI. Basically you are going to need to
loop through all of the adapters, using lineGetDevCaps. In this loop,
when you find the active one, call lineOpen. Then call
lineGetLineDevStatus. From that you should be able to get what you
need. If you still need help let me know and I will put together a
sample for you.

Matt
 
L

leibnizster

The project uses c#. I tried using Alex Feinman's TAPI wrapper but it
wouldn't work. When I initialized the OpenNETCF.Tapi.Tapi class it
failed. Any ideas? I just added the TapiLib.dll file to the resources
and I tried using something similar to what Alex said on another
thread:

Here is roughly what you want to do:

Tapi tapi = new Tapi();

int lineNo = tapi.Initialize();

Line line = null;

for( int i= 0; i < lineNo; i++)

{

LINEDEVCAPS dc;

if ( tapi.GetDevCaps(i, out dc) == 0 )

{

if ( dc.ProviderName == CellTSP.CELLTSP_PROVIDERINFO_STRING )

{

line = tapi.CreateLine(i, LINEMEDIAMODE.INTERACTIVEVOICE,
LINECALLPRIVILEGE.NONE);

}
}
}

if ( line != null )

{

LINEDEVSTATUS status = new LINEDEVSTATUS(1024);

status.Store();

NativeTapi.lineGetLineDevStatus(line.hLine, status.Data);

status.Load();

label1.Text = "Signal strength is: " + status.dwSignalLevel.ToString();

}

line.Dispose();

tapi.Shutdown();

--
Alex Feinman


Regards,
Gottfried
 
L

leibnizster

the program returns 0 at the following line:

int lineNo = tapi.Initialize();

the GPRS signal is active and I don't really know what the functions
are supposed to be doing. Anyway, the code doesn't work.
 
P

Peter Foot [MVP]

If your device is Windows Mobile 5.0 you can use
Microsoft.WindowsMobile.Status.SystemStatem.PhoneSignalStrength
To retrieve the strength as a percentage.

Peter
 
G

Guest

Unfortunately, that method is basically useless. It reports only very coarse
increments, e.g. 100%, 88%, 66%, 28%, 0%.

Furthermore, without a conversion to dBm, not a lot of value is contained in
the percentage value.

Can anyone tell me if TAPI reports more useful data?

Richard
 
G

Guest

Try the code sample below (warning this makes some assumptions about TAPI
buffer sizes that may need tweaking but that is because I did not want to
continuously negotiate with TAPI for buffer sizes). This sample outputs to a
console which may not be present on all CE/WM terminals. It will run anyway
but there will be no visible output. It works out dBm figures based on what
the AT command to the modem would have returned for the TAPI signal level
value provided.

===
#include <tapi.h>
#include <extapi.h>
#include <Ras.h>

TCHAR* LineStates[] =
{
TEXT("Unknown"),
TEXT("Off"),
TEXT("Rx Only"),
TEXT("Tx Only"),
TEXT("No Tx/Rx"),
TEXT("Full")
};

TCHAR* RegisterStates[] =
{
TEXT(""),
TEXT("Unknown"),
TEXT("Denied"),
TEXT("Not registered"),
TEXT("Registering"),
TEXT("Home"),
TEXT("Roaming"),
TEXT("Digital service"),
TEXT("Analog service")
};

TCHAR* GPRSClass[] =
{
TEXT("Unknown"),
TEXT("Voice & GPRS"),
TEXT("GSM data or GPRS"),
TEXT("Voice or GPRS"),
TEXT("GPRS only"),
TEXT("GSM only"),
};

TCHAR* SystemType[] =
{
TEXT("None"), // 0x00
TEXT("IS95A"), // 0x01
TEXT("IS95B"), // 0x02
TEXT("1XRTT"), // 0x04
TEXT("GSM"), // 0x08
TEXT("GPRS") // 0x10
};


const int TAPI_LOW_VERSION = 0x10003;
const int TAPI_HIGH_VERSION = 0x20002;
const int TAPI_LOW_EXT_VERSION = 0x10000;
const int TAPI_HIGH_EXT_VERSION = 0x10001;

void GetGPRSStatus( void )
{
HLINEAPP tapiHandle = 0;
DWORD numberDevices = 0;
DWORD tapiVersion = 0x00020000;
LINEINITIALIZEEXPARAMS lineInit;
DWORD tapiAPIVersion = 0;
DWORD tapiExtVersion = 0;
HLINE lineHandle = 0;

LONG err = 0;

lineInit.dwTotalSize = sizeof(LINEINITIALIZEEXPARAMS);
lineInit.dwOptions = LINEINITIALIZEEXOPTION_USEEVENT;

if( (err = lineInitializeEx( &tapiHandle, NULL, NULL, TEXT("GPRSStatus"),
&numberDevices, &tapiVersion, &lineInit)) == ERROR_SUCCESS )
{
for ( DWORD i = 0; i < numberDevices; i++ )
{
if ( (err = lineNegotiateAPIVersion( tapiHandle, i, TAPI_LOW_VERSION,
TAPI_HIGH_VERSION, &tapiAPIVersion, NULL )) == ERROR_SUCCESS )
{
if ( (err = lineNegotiateExtVersion( tapiHandle, i, tapiAPIVersion,
TAPI_LOW_EXT_VERSION, TAPI_HIGH_EXT_VERSION, &tapiExtVersion)) ==
ERROR_SUCCESS )
{
LINEDEVCAPS* lineDevCaps = (LINEDEVCAPS*) new char[sizeof(LINEDEVCAPS)
+ 1024];
lineDevCaps->dwTotalSize = sizeof(LINEDEVCAPS) + 1024;

if ( (err = lineGetDevCaps(tapiHandle, i, tapiAPIVersion,
tapiExtVersion, lineDevCaps)) == ERROR_SUCCESS )
{
if ( _wcsnicmp( (TCHAR*) (((char*) lineDevCaps) +
lineDevCaps->dwLineNameOffset), TEXT("Cellular Line"),
lineDevCaps->dwLineNameSize ) == 0 )
{
if ( (err = lineOpen( tapiHandle, i, &lineHandle, tapiAPIVersion,
tapiExtVersion, 0, LINECALLPRIVILEGE_MONITOR | LINECALLPRIVILEGE_OWNER,
LINEMEDIAMODE_INTERACTIVEVOICE | LINEMEDIAMODE_DATAMODEM, NULL )) ==
ERROR_SUCCESS )
{
LINEGENERALINFO* LineGeneralInfo = (LINEGENERALINFO*) new char[2048];
memset( LineGeneralInfo, 0, sizeof(LineGeneralInfo));
LineGeneralInfo->dwTotalSize = 2048;

if ( lineGetGeneralInfo( lineHandle, LineGeneralInfo ) ==
ERROR_SUCCESS)
{
TCHAR buffer[1024];
memset(buffer, 0, sizeof(buffer));
memcpy(buffer, ((char*) LineGeneralInfo) +
LineGeneralInfo->dwModelOffset, LineGeneralInfo->dwModelSize);
wprintf(TEXT("Model : %s\r\n"), buffer);

memset(buffer, 0, sizeof(buffer));
memcpy(buffer, ((char*) LineGeneralInfo) +
LineGeneralInfo->dwRevisionOffset, LineGeneralInfo->dwRevisionSize);
wprintf(TEXT("Revision : %s\r\n"), buffer);
}

delete[] LineGeneralInfo;

DWORD CurrentState = 0;
DWORD CurrentSupport = 0;

if ( lineGetEquipmentState( lineHandle, &CurrentState,
&CurrentSupport ) == ERROR_SUCCESS)
{
wprintf(TEXT("Radio Power: %s\r\n"), LineStates[CurrentState]);
}

DWORD RegisterStatus = 0;
lineGetRegisterStatus( lineHandle, &RegisterStatus );
wprintf(TEXT("Register : %s\r\n"), RegisterStates[RegisterStatus]);

LINEOPERATOR CurrentOperator;

if ( lineGetCurrentOperator( lineHandle, &CurrentOperator ) ==
ERROR_SUCCESS )
{
if (wcslen(CurrentOperator.lpszLongName) != 0 )
wprintf(TEXT("Network : %s\r\n"), CurrentOperator.lpszLongName);
else
wprintf(TEXT("Network : None\r\n"));
}

LINEDEVSTATUS DevStatus;
memset( &DevStatus, 0, sizeof(DevStatus));
DevStatus.dwTotalSize = sizeof(DevStatus);

if ( lineGetLineDevStatus(lineHandle, &DevStatus) == ERROR_SUCCESS)
{
int SignalLevel = 0;

if ( DevStatus.dwSignalLevel == 0 )
{
wprintf(TEXT("Signal : No signal\r\n") );
}
else if ( DevStatus.dwSignalLevel > 64225 )
{
wprintf(TEXT("Signal : >= 27 (-59)dBm\r\n") );
}
else
{
SignalLevel = (DevStatus.dwSignalLevel - 1310 ) / 2621 + 2;
int dBm = -113 + SignalLevel * 2;

wprintf(TEXT("Signal : %d (%d)dBm\r\n"), SignalLevel, dBm );
}
}

DWORD dwCurrentSystemType = 0;

if ( lineGetCurrentSystemType(lineHandle, &dwCurrentSystemType) ==
ERROR_SUCCESS)
{
if ( dwCurrentSystemType == 0 )
{
wprintf(TEXT("System Type: %s\r\n"),
SystemType[dwCurrentSystemType]);
}
else
{
wprintf(TEXT("System Type:"));

int i = 0x01;
int pos = 1;

while ( i < 0x020 )
{
if ( (i & dwCurrentSystemType) != 0 )
wprintf(TEXT(" %s"), SystemType[pos]);

i = i << 1;
++pos;
}

wprintf(TEXT("\r\n"));
}
}

DWORD dwClass = 0;

if ( lineGetGPRSClass(lineHandle, &dwClass) == ERROR_SUCCESS)
wprintf(TEXT("Class : %s\r\n"), GPRSClass[dwClass]);

err = lineClose( lineHandle );
delete[] lineDevCaps;
break;
}
}
}

delete[] lineDevCaps;
}
}
}

lineShutdown( tapiHandle );
}
}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top