Timo Scheffler <timo.scheff...@uni-oldenburg.de> writes:

> Wrong Link, here is the example:
>
> #!/usr/bin/env python
>
> import dbus
> import time
>
> # Wakeup in 60 seconds
> wakeuptime=str(time.time()+60)
>
> system_bus = dbus.SystemBus()
>
> rtc_object = system_bus.get_object('org.freesmartphone.odeviced',
> '/org/freesmartphone/Device/RealTimeClock/0')
> rtc_interface = dbus.Interface(rtc_object,
> dbus_interface='org.freesmartphone.Device.RealTimeClock')
> rtc_interface.SetWakeupTime(wakeuptime)


atd-over-fso works on top of org.freesmartphone.Time.Alarm
http://git.freesmartphone.org/?p=specs.git;a=blob_plain;f=html/org.freesmartphone.Time.Alarm.html;hb=HEAD
and should be equivalent to to attached aldbus.py script, you will have
stop atd-over-fso (/etc/init.d/atd stop) as the script uses its dbus
name.  (atd-over-fso also sets rtc from time(NULL) when setting the
alarm).

You can set the alarm time from the console and list the alarms to
compared displayed timestamps with "time.time()":

$ ffalarms -s 7:00
$ ffalarms -l
 1240981200  Wed Apr 29 07:00:00 2009
$ TZ=UTC ffalarms -l
 1240981200  Wed Apr 29 05:00:00 2009
$ ls -l /var/spool/at/
-rwxr-xr-x    1 root     root         1320 Apr 28 21:01 1240981200.ffalarms.6399
p-w--w--w-    1 root     root            0 Apr 28 21:01 trigger

it may be some kind of timezone problem, you may also try to set alarm
an hour before/later to see whether this will wake up the phone.

# see: /usr/share/doc/python-dbus-doc/examples

import sys
import time

import dbus
import dbus.service
import gobject
from dbus.mainloop.glib import DBusGMainLoop

DBUS_NAME = "org.openmoko.projects.ffalarms.atd"


class AlarmNotification(dbus.service.Object):

    @dbus.service.method('org.freesmartphone.Notification', # interface
                        in_signature='', out_signature='')
    def Alarm(self):
        print 'Alarm', time.time()


def get_alarm(bus):
    o = bus.get_object('org.freesmartphone.otimed', '/org/freesmartphone/Time/Alarm')
    return dbus.Interface(o, 'org.freesmartphone.Time.Alarm')


def got_signal(name, old_owner, new_owner):
    if name == 'org.freesmartphone.otimed' and new_owner:
        print 'owner of otimed changed'
        # so we have to get new owner and reset the alarm
        alarm = get_alarm(bus)
        alarm.SetAlarm(DBUS_NAME, alarm_time)
        print 'signal', (name, old_owner, new_owner)
        now = time.time()
        print 'at %s: reset alarm to %s' % (now, alarm_time)
        if now > alarm_time:
            print 'alarm %s passed' % alarm_time


def main():
   if len(sys.argv) > 1:
      sec = int(sys.argv[1])
   else:
      sec = 60
   dbus_loop = DBusGMainLoop(set_as_default=True)
   bus = dbus.SystemBus()
   print bus.get_unique_name(), DBUS_NAME
   bus.request_name(DBUS_NAME)
   AlarmNotification(bus, '/')
   alarm = get_alarm(bus)
   now = time.time()
   alarm_time = now + sec
   alarm.SetAlarm(DBUS_NAME, alarm_time)
   print 'at %s alarm set to: now + %s = %s' % (now, sec, alarm_time)
   # org.freedesktop.DBus.NameOwnerChanged
   bus.add_signal_receiver(got_signal, 'NameOwnerChanged', bus_name='org.freedesktop.DBus')
   loop = gobject.MainLoop()
   loop.run()


if __name__ == '__main__':
    main()
_______________________________________________
Openmoko community mailing list
community@lists.openmoko.org
http://lists.openmoko.org/mailman/listinfo/community

Reply via email to