Active Topics

 


Reply
Thread Tools
Posts: 3 | Thanked: 6 times | Joined on Feb 2010 @ Paris
#1
Hi,

I need to detect the network type I'm connected through on a N900, in order to adapt the size of what I'm downloading to the connection speed.

I can already find out whether I'm connected through WiFi or cellular data, but in the latter case I would need to know what's the "generation" of that cellular connection (2.5G, 3G or 3.5G ?) in order to estimate the throughput I can expect.

There's got to be a way to get that information since the status area displays it, but so far I haven't been able to find it.

Any hint is welcome,
Thanks in advance
 

The Following User Says Thank You to rbailly For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#2
yup check my healthcheck application

Uses Python / pymaemo - and pulls out Cell info connection type

A good example of the code can be found here though - http://repository.maemo.org/extras-d...urce/n/netmon/
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 

The Following 2 Users Say Thank You to noobmonkey For This Useful Post:
Posts: 3 | Thanked: 6 times | Joined on Feb 2010 @ Paris
#3
Thanks, that was indeed really helpful. Here's the code I came up with, in case someone else is interested:

Code:
GError* error = NULL;
DBusGConnection* dbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
DBusGProxy* phoneNetProxy = dbus_g_proxy_new_for_name(dbus, "com.nokia.phone.net", "/com/nokia/phone/net", "Phone.Net");

guchar status;
guint  lac;
guint  cellId;
guint  operatorCode;
guint  countryCode;
guchar networkType;
guchar supportedServices;
gint   netError;
dbus_g_proxy_call(phoneNetProxy, "get_registration_status", &error,
                  G_TYPE_INVALID,
                  G_TYPE_UCHAR, &status,
                  G_TYPE_UINT,  &lac,
                  G_TYPE_UINT,  &cellId,
                  G_TYPE_UINT,  &operatorCode,
                  G_TYPE_UINT,  &countryCode,
                  G_TYPE_UCHAR, &networkType,
                  G_TYPE_UCHAR, &supportedServices,
                  G_TYPE_INT,   &netError,
                  G_TYPE_INVALID);

g_object_unref(phoneNetProxy);

if (supportedServices & 0x08) return "3.5G"; // HSDPA
if (supportedServices & 0x04) return "3G";   // EGPRS
if (supportedServices & 0x01) return "2.5G"; // GPRS
if (supportedServices & 0x02) return "2G";   // CS (Circuit Switched)
return NULL;
 

The Following User Says Thank You to rbailly For This Useful Post:
noobmonkey's Avatar
Posts: 3,203 | Thanked: 1,391 times | Joined on Nov 2009 @ Worthing, England
#4
Originally Posted by rbailly View Post
Thanks, that was indeed really helpful. Here's the code I came up with, in case someone else is interested:

Code:
GError* error = NULL;
DBusGConnection* dbus = dbus_g_bus_get(DBUS_BUS_SYSTEM, &error);
DBusGProxy* phoneNetProxy = dbus_g_proxy_new_for_name(dbus, "com.nokia.phone.net", "/com/nokia/phone/net", "Phone.Net");

guchar status;
guint  lac;
guint  cellId;
guint  operatorCode;
guint  countryCode;
guchar networkType;
guchar supportedServices;
gint   netError;
dbus_g_proxy_call(phoneNetProxy, "get_registration_status", &error,
                  G_TYPE_INVALID,
                  G_TYPE_UCHAR, &status,
                  G_TYPE_UINT,  &lac,
                  G_TYPE_UINT,  &cellId,
                  G_TYPE_UINT,  &operatorCode,
                  G_TYPE_UINT,  &countryCode,
                  G_TYPE_UCHAR, &networkType,
                  G_TYPE_UCHAR, &supportedServices,
                  G_TYPE_INT,   &netError,
                  G_TYPE_INVALID);

g_object_unref(phoneNetProxy);

if (supportedServices & 0x08) return "3.5G"; // HSDPA
if (supportedServices & 0x04) return "3G";   // EGPRS
if (supportedServices & 0x01) return "2.5G"; // GPRS
if (supportedServices & 0x02) return "2G";   // CS (Circuit Switched)
return NULL;
Nicely done - and thank you for reposting back - allways good to get extra info. - if it is not already on the wiki - may be worth you posting an example page on there?
__________________
----------- Follow me on Twitter here
----------- My Photography Website and Blog is here
----------- Author of the N900 Health Check Application ----------- New Version in Extras Devel (Dec 2010 - 2.9.10)
----------- Are you on the N900 World Map? - http://pininthemap.com/maemo - masterpin: shotgun
----------- What apps do you want to see on the n900 or in MeeGo in the future? -
 

The Following User Says Thank You to noobmonkey For This Useful Post:
Posts: 60 | Thanked: 23 times | Joined on Jan 2010
#5
Thanks for posting that!

Can you please post code for how to detect if the current connection is wifi or cellular ?
 
Posts: 3 | Thanked: 6 times | Joined on Feb 2010 @ Paris
#6
Originally Posted by tmsha View Post
Thanks for posting that!

Can you please post code for how to detect if the current connection is wifi or cellular ?
Ok, here we go. Please note that this is code I wrote on the fly by copying and pasting parts of my own code. It compiles fine but I haven't tested it.

You can also figure out whether you're connected through bluetooth by testing for additional bearer strings as documented in libconic.

Code:
#include <conic/conicconnection.h>
#include <conic/conicconnectionevent.h>
#include <conic/conicevent.h>
#include <glib/gmain.h>
#include <string.h>
	

enum ConnectionType
{
    CONN_TYPE_UNKNOWN,
    CONN_TYPE_WIFI,
    CONN_TYPE_CELLULAR,
};


struct ConnectionEventData
{
    GMainLoop*     loop;
    ConnectionType type;
};


void ConnectionEventCallback(ConIcConnection* /*connection*/, ConIcConnectionEvent* event, gpointer user_data)
{
    ConnectionEventData* data = static_cast<ConnectionEventData*>(user_data);

    bool connected = (con_ic_connection_event_get_status(event) == CON_IC_STATUS_CONNECTED);
    if (connected)
    {
        const gchar* bearer = con_ic_event_get_bearer_type(CON_IC_EVENT(event));
        if (strcmp(bearer,CON_IC_BEARER_WLAN_ADHOC)==0 || strcmp(bearer,CON_IC_BEARER_WLAN_INFRA)==0)
            data->type =  CONN_TYPE_WIFI;
        else if (strcmp(bearer,"GPRS") == 0)
            data->type = CONN_TYPE_CELLULAR;
    }

    g_main_loop_quit(data->loop);
}


ConnectionType GetConnectionType()
{
    ConnectionEventData data;
    data.loop = g_main_loop_new(NULL, FALSE);
    data.type = CONN_TYPE_UNKNOWN;

    // Create connection
    ConIcConnection* connection = con_ic_connection_new();
    g_object_ref_sink(connection);
    g_signal_connect(G_OBJECT(connection), "connection-event", G_CALLBACK(ConnectionEventCallback), &data);

    // Ask whether we're already connected
    con_ic_connection_connect(connection, CON_IC_CONNECT_FLAG_AUTOMATICALLY_TRIGGERED);

    // Run our own event loop to wait for notification
    g_main_loop_run(data.loop);
    g_main_loop_unref(data.loop);

    g_object_unref(connection);
    return data.type;
}
 

The Following 4 Users Say Thank You to rbailly For This Useful Post:
Reply


 
Forum Jump


All times are GMT. The time now is 08:33.