FSO scripts

From Openmoko

(Difference between revisions)
Jump to: navigation, search
m (External links)
 
(2 intermediate revisions by one user not shown)
Line 89: Line 89:
  
 
</pre>
 
</pre>
 +
 +
=== Dialing calls ===
 +
 +
<pre>
 +
import dbus
 +
 +
bus = dbus.SystemBus()
 +
ogsmd = bus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device" )
 +
Call = dbus.Interface( ogsmd, "org.freesmartphone.GSM.Call" )
 +
 +
print "id", Call.Initiate(number, "voice")
 +
</pre>
 +
 +
=== External links ===
 +
 +
* DBus docs for call methods and signals are [http://docs.freesmartphone.org/org.freesmartphone.GSM.Call.html here].
  
 
== GPS ==
 
== GPS ==
 +
 +
=== External links ===
 +
 +
* DBus docs for GPS methods and signals are in several pages:
 +
** [http://docs.freesmartphone.org/org.freedesktop.Gypsy.Accuracy.html org.freedesktop.Gypsy.Accuracy]
 +
** [http://docs.freesmartphone.org/org.freedesktop.Gypsy.Course.html org.freedesktop.Gypsy.Course]
 +
** [http://docs.freesmartphone.org/org.freedesktop.Gypsy.Device.html org.freedesktop.Gypsy.Device]
 +
** [http://docs.freesmartphone.org/org.freedesktop.Gypsy.Position.html org.freedesktop.Gypsy.Position]
 +
** [http://docs.freesmartphone.org/org.freedesktop.Gypsy.Time.html org.freedesktop.Gypsy.Time]
 +
 
== Events ==
 
== Events ==
 +
 +
=== External links ===
 +
 +
* DBus docs for event methods are [http://docs.freesmartphone.org/org.freesmartphone.Events.html here].
 +
 
== INPUT ==
 
== INPUT ==
Accellerometers go here
+
 
 +
=== External links ===
 +
 
 +
* DBus docs for orientation (using accellerometers) are [http://docs.freesmartphone.org/org.freesmartphone.Device.Orientation.html here].
  
 
[[Category:FSO]]
 
[[Category:FSO]]

Latest revision as of 14:10, 14 March 2011

Contents

[edit] Why

FSO is a great framework. But at the moment, developers are concentrating on the frameworkd daemon. This leaves us (FSO not SHR users) in a bind. So here are some scripts to help your daily life along.

[edit] GSM

[edit] Logging calls

Uses SQLlite to log all your calls - missed, received, dialled out. At the moment, the database is in roots home. This can be moved to a standard place Example use

#Most called numbers
sqlite> select msisdn,sum(duration) from call_log where direction=0  group by msisdn order by sum(duration) desc limit 5;
073xxxxxxx|16507.622120142
072xxxxxxx|2735.2764070034
0722xxxxxx|2689.02251005173
0751xxxxxx|1292.24268722534
0721xxxxxx|1139.27544236183

Here's the database schema

sqlite> .schema call_log
CREATE TABLE call_log (id integer PRIMARY KEY AUTOINCREMENT ,
msisdn text,
direction int,
duration float,
active int, eventtime, int);
sqlite> 

Here's the script

import dbus
import dbus.mainloop 
import dbus.mainloop.glib
import gobject 
import subprocess
import time
import sqlite3
                                                                                                                                                                                                                                               
starttime=0
seen=0
lastrow=0
def onCallStatus( index, status, properties ):
        global seen,starttime,lastrow
        conn = sqlite3.connect('/home/root/.logs.sqlite')
        c = conn.cursor()

        print "\n","--"*20,"\n","Index:",index,": Status:",status,": Properties:",properties
        print "seen:",seen,"Startime:",starttime

        if status == "incoming":
                if not seen:
                        print "Incoming",properties
                        sql="insert into call_log (msisdn,direction,duration,active,eventtime) values(?,?,?,?,(SELECT strftime('%s','now')))";
                        c.execute(sql,(properties['peer'],1,0,0))
                        sql="SELECT last_insert_rowid()"
                        lastrow=c.execute(sql).fetchone()[0]
                        seen=1
        if status == "outgoing":
                if not seen:
                        print "outgoing",properties
                        sql="insert into call_log (msisdn,direction,duration,active,eventtime) values(?,?,?,?,(SELECT strftime('%s','now')))";
                        c.execute(sql,(properties['peer'],0,0,0))
                        sql="SELECT last_insert_rowid()"
                        lastrow=c.execute(sql).fetchone()[0]
                        seen=1
        if status == "release":
                if starttime:
                        sql="update call_log set duration=?, active=? where id=?";
                        talktime = time.time() - starttime
                        print "Talk time: ",talktime," For row",lastrow
                        c.execute(sql,(talktime,1,lastrow))
                        starttime=0
                seen=0
        if status == "active":
                starttime=time.time()
        conn.commit()
        c.close()


dbus.mainloop.glib.DBusGMainLoop( set_as_default=True )                                                                                                                                                                                        
mainloop = gobject.MainLoop()                                                                                                                                                                                                                  
bus = dbus.SystemBus()                                                                                                                                                                                                                         
bus.add_signal_receiver( onCallStatus,
                         "CallStatus",
                         "org.freesmartphone.GSM.Call",
                         "org.freesmartphone.ogsmd", 
                         "/org/freesmartphone/GSM/Device" )                                                                                             
mainloop.run()       

[edit] Dialing calls

import dbus

bus = dbus.SystemBus()
ogsmd = bus.get_object( "org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device" )
Call = dbus.Interface( ogsmd, "org.freesmartphone.GSM.Call" )

print "id", Call.Initiate(number, "voice")

[edit] External links

  • DBus docs for call methods and signals are here.

[edit] GPS

[edit] External links

[edit] Events

[edit] External links

  • DBus docs for event methods are here.

[edit] INPUT

[edit] External links

  • DBus docs for orientation (using accellerometers) are here.
Personal tools

Why

FSO is a great framework. But at the moment, developers are concentrating on the frameworkd daemon. This leaves us (FSO not SHR users) in a bind. So here are some scripts to help your daily life along.

GSM

Logging calls

Uses SQLlite to log all your calls - missed, received, dialled out. At the moment, the database is in roots home. This can be moved to a standard place Example use

#Most called numbers
sqlite> select msisdn,sum(duration) from call_log where direction=0  group by msisdn order by sum(duration) desc limit 5;
073xxxxxxx|16507.622120142
072xxxxxxx|2735.2764070034
0722xxxxxx|2689.02251005173
0751xxxxxx|1292.24268722534
0721xxxxxx|1139.27544236183

Here's the database schema

sqlite> .schema call_log
CREATE TABLE call_log (id integer PRIMARY KEY AUTOINCREMENT ,
msisdn text,
direction int,
duration float,
active int, eventtime, int);
sqlite> 

Here's the script

import dbus
import dbus.mainloop 
import dbus.mainloop.glib
import gobject 
import subprocess
import time
import sqlite3
                                                                                                                                                                                                                                               
starttime=0
seen=0
lastrow=0
def onCallStatus( index, status, properties ):
        global seen,starttime,lastrow
        conn = sqlite3.connect('/home/root/.logs.sqlite')
        c = conn.cursor()

        print "\n","--"*20,"\n","Index:",index,": Status:",status,": Properties:",properties
        print "seen:",seen,"Startime:",starttime

        if status == "incoming":
                if not seen:
                        print "Incoming",properties
                        sql="insert into call_log (msisdn,direction,duration,active,eventtime) values(?,?,?,?,(SELECT strftime('%s','now')))";
                        c.execute(sql,(properties['peer'],1,0,0))
                        sql="SELECT last_insert_rowid()"
                        lastrow=c.execute(sql).fetchone()[0]
                        seen=1
        if status == "outgoing":
                if not seen:
                        print "outgoing",properties
                        sql="insert into call_log (msisdn,direction,duration,active,eventtime) values(?,?,?,?,(SELECT strftime('%s','now')))";
                        c.execute(sql,(properties['peer'],0,0,0))
                        sql="SELECT last_insert_rowid()"
                        lastrow=c.execute(sql).fetchone()[0]
                        seen=1
        if status == "release":
                if starttime:
                        sql="update call_log set duration=?, active=? where id=?";
                        talktime = time.time() - starttime
                        print "Talk time: ",talktime," For row",lastrow
                        c.execute(sql,(talktime,1,lastrow))
                        starttime=0
                seen=0
        if status == "active":
                starttime=time.time()
        conn.commit()
        c.close()


dbus.mainloop.glib.DBusGMainLoop( set_as_default=True )                                                                                                                                                                                        
mainloop = gobject.MainLoop()                                                                                                                                                                                                                  
bus = dbus.SystemBus()                                                                                                                                                                                                                         
bus.add_signal_receiver( onCallStatus,
                         "CallStatus",
                         "org.freesmartphone.GSM.Call",
                         "org.freesmartphone.ogsmd", 
                         "/org/freesmartphone/GSM/Device" )                                                                                             
mainloop.run()       

GPS

Events

INPUT

Accellerometers go here