r242 - trunk/software/pyneod
smartphones-commits at lists.linuxtogo.org
smartphones-commits at lists.linuxtogo.org
Tue Apr 22 15:32:22 CEST 2008
Author: emdete
Date: 2008-04-22 15:32:21 +0200 (Tue, 22 Apr 2008)
New Revision: 242
Modified:
trunk/software/pyneod/Makefile
trunk/software/pyneod/pyggld.py
trunk/software/pyneod/pygpsd.py
trunk/software/pyneod/pyneod.ini
trunk/software/pyneod/pyneod.py
trunk/software/pyneod/pypppd.py
Log:
add location cache db
gprs startup corrects resolv.conf update errors of system
add SetLocation(cellid) to location interface
Modified: trunk/software/pyneod/Makefile
===================================================================
--- trunk/software/pyneod/Makefile 2008-04-22 12:44:13 UTC (rev 241)
+++ trunk/software/pyneod/Makefile 2008-04-22 13:32:21 UTC (rev 242)
@@ -1,9 +1,10 @@
#!/usr/bin/env make -f
.PHONY: run
run:
- python2.5 -u ./test.py org.bluez /org/bluez
+ #python2.5 -u ./test.py org.bluez /org/bluez
+ ./pyllbd.py
.PHONY: dbg
dbg:
- rsync --verbose --archive . root at fic-gta02:/usr/share/pyneod/.
+ rsync --verbose --archive . root at fic-gta01:/usr/share/pyneod/.
Modified: trunk/software/pyneod/pyggld.py
===================================================================
--- trunk/software/pyneod/pyggld.py 2008-04-22 12:44:13 UTC (rev 241)
+++ trunk/software/pyneod/pyggld.py 2008-04-22 13:32:21 UTC (rev 242)
@@ -7,13 +7,13 @@
from urllib2 import Request, urlopen
from struct import pack, unpack, calcsize
-from time import time
-from gobject import timeout_add
-#from gdbm import open as db_open
+from gdbm import open as db_open
from base import log_info, log_debug, config, LOG_ERR, LOG_WARNING, LOG_INFO, LOG_DEBUG, LOG, dedbusmap
from freesmartphone import *
-# dbus-send --system --print-reply --type=method_call --dest=org.mobile /org/mobile/GoogleLocation org.mobile.Location.GetPosition
+'''
+dbus-send --system --print-reply --type=method_call --dest=org.mobile /org/mobile/GoogleLocation org.mobile.Location.SetPosition string:262.2.144.26993
+'''
class GoogleLocation(NotifyObject):
def __init__(self, bus):
@@ -22,98 +22,39 @@
object_path='/org/mobile/GoogleLocation',
bus_name=BusName(DBUS_NAME, self.bus),
)
- self.ggl_fix = False
- self.gps_fix = False # dont get active - we don't know if gps has a fix but it will tell us soon
- self.gsm_fix = False
self.latitude = 0.0
self.longitude = 0.0
- self.lac = None
- self.ci = None
- self.gps = None
- self.gsm = None
- #try: self.db = db_open('/media/card/location.db', 'wf')
- #except: self.db = db_open('/media/card/location.db', 'cf')
- timeout_add(7000, self.__connect_signals)
+ self.cellid = None
+ self.fix = False
+ try: self.db = db_open(config.get('ggl', 'database'), 'wf')
+ except: self.db = db_open(config.get('ggl', 'database'), 'cf')
- @method(DIN_LOCATION, '', 'a{sv}')
- def GetPosition(self):
- LOG(LOG_DEBUG, __name__, 'GetPosition')
- self.gps.get_position(reply_handler=self.fix_changed, error_handler=self.__dbus_reply, )
- self.gsm.get_network_status(reply_handler=self.network_status, error_handler=self.__dbus_reply, )
- return dict(latitude=self.latitude, longitude=self.longitude, gglfix=self.ggl_fix and 1 or 0, )
+ @method(DIN_LOCATION, 's', 'a{sv}')
+ def SetPosition(self, cellid):
+ LOG(LOG_DEBUG, __name__, 'SetPosition')
+ if self.cellid != cellid:
+ mcc, mnc, lac, ci, = [int(n) for n in cellid.split('.')]
+ key = pack('!iiii', mcc, mnc, lac, ci, )
+ if self.db.has_key(key):
+ LOG(LOG_INFO, __name__, '__locate', 'from db')
+ self.latitude, self.longitude = [float(n) / 1000000.0 for n in unpack('!ii', self.db[key])]
+ self.fix = True
+ else:
+ self.fix, self.latitude, self.longitude = GoogleLocation.__locate(mcc, mnc, lac, ci, )
+ self.cellid = cellid
+ self.db[key] = pack('!ii', int(self.latitude*1000002), int(self.longitude*1000000))
+ content = dict(latitude=self.latitude, longitude=self.longitude, fix=self.fix and 1 or 0, )
+ self.Position(content)
+ return content
@notify(DIN_LOCATION, 'a{sv}')
def Position(self, content):
LOG(LOG_DEBUG, __name__, 'Position', content)
- def fix_changed(self, content):
- content = dedbusmap(content)
- LOG(LOG_DEBUG, __name__, 'fix_changed', content)
- self.gps_fix = int(content.get('fix', self.gps_fix)) == 1
- if not self.gps_fix:
- LOG(LOG_DEBUG, __name__, 'gps_fix', self.gps_fix)
- if self.gsm_fix:
- LOG(LOG_DEBUG, __name__, 'gsm_fix', self.gsm_fix)
- if not self.ggl_fix:
- self.ggl_fix, self.latitude, self.longitude = self.__locate(self.lac, self.ci)
- self.Position(dict(latitude=self.latitude, longitude=self.longitude, gglfix=self.ggl_fix and 1 or 0, ))
- LOG(LOG_DEBUG, __name__, 'fix_changed', self.__dict__)
-
- def network_status(self, content):
- content = dedbusmap(content)
- LOG(LOG_DEBUG, __name__, 'network_status in', content)
- self.gsm_fix = int(content.get('stat', self.gsm_fix)) in (1, 5, )
- if self.gsm_fix:
- LOG(LOG_DEBUG, __name__, 'gsm_fix', self.gsm_fix)
- lac = int(content['lac'], 16)
- ci = int(content['ci'], 16)
- if not self.ggl_fix or self.lac != lac or self.ci != ci:
- LOG(LOG_DEBUG, __name__, 'lac/ci changed', self.ggl_fix, self.lac, lac, self.ci, ci, )
- if not self.gps_fix:
- LOG(LOG_DEBUG, __name__, 'gps_fix', self.gps_fix)
- self.ggl_fix, self.latitude, self.longitude = self.__locate(lac, ci)
- else:
- self.ggl_fix = False
- self.ggl_fix = 0.0
- self.latitude = 0.0
- self.lac = lac
- self.ci = ci
- self.Position(dict(latitude=self.latitude, longitude=self.longitude, gglfix=self.ggl_fix and 1 or 0, ))
- else:
- self.lac = None
- self.ci = None
- LOG(LOG_DEBUG, __name__, 'network_status self', self.__dict__)
-
- def __dbus_reply(self, *values):
- LOG(LOG_DEBUG, __name__, '__dbus_reply', values)
-
- def __connect_signals(self):
- LOG(LOG_DEBUG, __name__, '__connect_signals')
- try:
- if self.gps is None:
- self.gps = self.bus.get_object(DBUS_NAME, '/org/mobile/GpsLocation')
- self.gps.connect_to_signal('Position', self.fix_changed, dbus_interface=DIN_LOCATION)
- self.gps = Interface(self.gps, DIN_LOCATION)
- self.gps.GetPosition(reply_handler=self.fix_changed, error_handler=self.__dbus_reply, )
- if self.gsm is None:
- self.gsm = self.bus.get_object(DBUS_NAME, '/org/mobile/GsmPhone')
- self.gsm.connect_to_signal('NetworkStatus', self.network_status, dbus_interface=DIN_PHONE)
- self.gsm = Interface(self.gsm, DIN_PHONE)
- self.gsm.NetworkGetStatus(reply_handler=self.network_status, error_handler=self.__dbus_reply, )
- return False
- except Exception, e:
- LOG(LOG_ERR, __name__, 'dbus error', e)
- return True
-
@staticmethod
- def __locate(lac, ci):
+ def __locate(mcc, mnc, lac, ci):
LOG(LOG_DEBUG, __name__, '__locate', lac, ci)
try:
-# key = '%s:%s'% (lac, ci, )
-# if self.db.haskey(key):
-# LOG(LOG_INFO, __name__, '__locate', 'from db')
-# t, latitude, longitude = map(float, db[key].split(':'))
-# return True, latitude, longitude
country = 'en'
user_agent = 'Sony_Ericsson-K810'
version = '1.3.1'
@@ -162,7 +103,6 @@
latitude, longitude, _, _, _ = unpack('!iiiih', data)
latitude /= 1000000.0
longitude /= 1000000.0
-# self.db[key] = '%d:%f:%f'% (0, latitude, longitude, )
LOG(LOG_DEBUG, __name__, '__locate', latitude, longitude)
return True, latitude, longitude
except Exception, e:
Modified: trunk/software/pyneod/pygpsd.py
===================================================================
--- trunk/software/pyneod/pygpsd.py 2008-04-22 12:44:13 UTC (rev 241)
+++ trunk/software/pyneod/pygpsd.py 2008-04-22 13:32:21 UTC (rev 242)
@@ -177,6 +177,10 @@
def get_signal_strength(self):
return self.in_view and (float(sum(self.ss[:self.in_view])) / self.in_view) or 0.0
+ @method(DIN_LOCATION, 's', 'a{sv}')
+ def SetPosition(self, cellid):
+ raise Exception('not implemented')
+
@notify(DIN_LOCATION, 'a{sv}')
def Position(self, _position):
LOG(LOG_DEBUG, __name__, 'Position', _position)
Modified: trunk/software/pyneod/pyneod.ini
===================================================================
--- trunk/software/pyneod/pyneod.ini 2008-04-22 12:44:13 UTC (rev 241)
+++ trunk/software/pyneod/pyneod.ini 2008-04-22 13:32:21 UTC (rev 242)
@@ -14,12 +14,16 @@
poll_interval = 7
[gps]
-udp_port =
-#9000
-serial_device = /dev/ttySAC1
+udp_port = 9000
+serial_device =
+#/dev/ttySAC1
[ggl]
+database = /media/card/zad/location.google.db
[ent]
poll_interval = 300
database = /media/card/zad/entry.db
+
+[llb]
+database = /media/card/zad/location.local.db
Modified: trunk/software/pyneod/pyneod.py
===================================================================
--- trunk/software/pyneod/pyneod.py 2008-04-22 12:44:13 UTC (rev 241)
+++ trunk/software/pyneod/pyneod.py 2008-04-22 13:32:21 UTC (rev 242)
@@ -48,6 +48,11 @@
from pyentd import Entry
daemons.append(Entry(bus))
except Exception, e: LOG(LOG_ERR, __name__, 'pyentd', e)
+if has_section('llb'):
+ try:
+ from pyllbd import LocalLocation
+ daemons.append(LocalLocation(bus))
+ except Exception, e: LOG(LOG_ERR, __name__, 'pyllbd', e)
if has_section('ppp'):
try:
from pypppd import Gprs
Modified: trunk/software/pyneod/pypppd.py
===================================================================
--- trunk/software/pyneod/pypppd.py 2008-04-22 12:44:13 UTC (rev 241)
+++ trunk/software/pyneod/pypppd.py 2008-04-22 13:32:21 UTC (rev 242)
@@ -30,48 +30,54 @@
#'OK' 'AT+CPAS'\
class Gprs(NotifyObject):
- __chap_secrets_filename = '/etc/ppp/chap-secrets'
- __chap_secrets_content = '* * "%s" *\n'% ''
- __pap_secrets_filename = '/etc/ppp/pap-secrets'
- __pap_secrets_content = '* * "%s" *\n'% ''
__init_filename = '/var/tmp/gprs-connect-chat'
- __init_content = r'''#!/bin/sh -e
- exec /usr/sbin/chat -v\
- 'ABORT' 'BUSY'\
- 'ABORT' 'DELAYED'\
- 'ABORT' 'ERROR'\
- 'ABORT' 'NO ANSWER'\
- 'ABORT' 'NO CARRIER'\
- 'ABORT' 'NO DIALTONE'\
- 'ABORT' 'RINGING'\
- 'ABORT' 'VOICE'\
- 'TIMEOUT' '3'\
- '' 'ATZ'\
- 'OK-\k\k\k\d+++ATH-OK' 'ATE0'\
- 'OK' 'AT+CMEE=2'\
- 'OK' 'AT+CPIN?'\
- 'READY' '\c'\
- 'OK' 'AT+CGDCONT=1,"IP","%s"'\
- 'TIMEOUT' '180'\
- 'OK' 'ATD*99#'\
- 'CONNECT' '\d\c'
- '''% config.get('ppp', 'apn')
__hangup_filename = '/var/tmp/gprs-disconnect-chat'
- __hangup_content = r'''#!/bin/sh
- exec /usr/sbin/chat -v\
- 'ABORT' 'OK'\
- 'ABORT' 'BUSY'\
- 'ABORT' 'DELAYED'\
- 'ABORT' 'NO ANSWER'\
- 'ABORT' 'NO CARRIER'\
- 'ABORT' 'NO DIALTONE'\
- 'ABORT' 'VOICE'\
- 'ABORT' 'ERROR'\
- 'ABORT' 'RINGING'\
- 'TIMEOUT' '60'\
- '' '\k\k\k\d+++ATH'\
- 'NO CARRIER-AT-OK' ''
- '''
+ __patch_files = {
+ __init_filename: r'''#!/bin/sh -e
+exec /usr/sbin/chat -v\
+ 'ABORT' 'BUSY'\
+ 'ABORT' 'DELAYED'\
+ 'ABORT' 'ERROR'\
+ 'ABORT' 'NO ANSWER'\
+ 'ABORT' 'NO CARRIER'\
+ 'ABORT' 'NO DIALTONE'\
+ 'ABORT' 'RINGING'\
+ 'ABORT' 'VOICE'\
+ 'TIMEOUT' '3'\
+ '' 'ATZ'\
+ 'OK-\k\k\k\d+++ATH-OK' 'ATE0'\
+ 'OK' 'AT+CMEE=2'\
+ 'OK' 'AT+CPIN?'\
+ 'READY' '\c'\
+ 'OK' 'AT+CGDCONT=1,"IP","%s"'\
+ 'TIMEOUT' '180'\
+ 'OK' 'ATD*99#'\
+ 'CONNECT' '\d\c'
+'''% config.get('ppp', 'apn'),
+ '/etc/ppp/chap-secrets': '* * "%s" *\n'% '',
+ '/etc/ppp/pap-secrets': '* * "%s" *\n'% '',
+ '/etc/ppp/ip-up.d/08setupdns': '''#!/bin/sh -e
+cp /var/run/ppp/resolv.conf /etc/resolv.conf
+''',
+ '/etc/ppp/ip-down.d/92removedns': '''#!/bin/sh -e
+echo nameserver 127.0.0.1 > /etc/resolv.conf
+''',
+ __hangup_filename: r'''#!/bin/sh -e
+exec /usr/sbin/chat -v\
+ 'ABORT' 'OK'\
+ 'ABORT' 'BUSY'\
+ 'ABORT' 'DELAYED'\
+ 'ABORT' 'NO ANSWER'\
+ 'ABORT' 'NO CARRIER'\
+ 'ABORT' 'NO DIALTONE'\
+ 'ABORT' 'VOICE'\
+ 'ABORT' 'ERROR'\
+ 'ABORT' 'RINGING'\
+ 'TIMEOUT' '60'\
+ '' '\k\k\k\d+++ATH'\
+ 'NO CARRIER-AT-OK' ''
+''',
+ }
__pppd_command = '/usr/sbin/pppd'
__pppd_options = [
'115200',
@@ -111,14 +117,8 @@
self.last_status = dict(device='')
timeout_add(12 * 1000, self.__poll)
- def __sig_child(self, no, frame):
- LOG(LOG_DEBUG, __name__, '__sig_child')
-
-
def __child_watch(self, *args):
print '__child_watch', args
- #system('ifdown usb0')
- #system('ifup usb0')
@method(DIN_NETWORK, 'b', '')
def Activate(self, on):
@@ -133,20 +133,12 @@
if not self.port: raise Exception('no device')
# go direct self.port = '/dev/ttySAC0'
LOG(LOG_INFO, __name__, 'Activate got port', self.port)
- f = open(Gprs.__chap_secrets_filename, 'w')
- f.write(Gprs.__chap_secrets_content)
- f.close()
- f = open(Gprs.__pap_secrets_filename, 'w')
- f.write(Gprs.__pap_secrets_content)
- f.close()
- f = open(Gprs.__init_filename, 'w')
- f.write(Gprs.__init_content)
- f.close()
- chmod(Gprs.__init_filename, S_IRWXU|S_IRWXG|S_IRWXO)
- f = open(Gprs.__hangup_filename, 'w')
- f.write(Gprs.__hangup_content)
- f.close()
- chmod(Gprs.__hangup_filename, S_IRWXU|S_IRWXO|S_IRWXO)
+ for filename, content in Gprs.__patch_files.items():
+ LOG(LOG_DEBUG, __name__, 'change file for our needs:', filename);
+ f = open(filename, 'w')
+ f.write(content)
+ f.close()
+ chmod(filename, S_IRWXU|S_IRWXO|S_IRWXO)
self.cpid, _, _, _ = spawn_async(
[Gprs.__pppd_command, self.port, ] + Gprs.__pppd_options,
standard_input=False, standard_output=False, standard_error=False,
@@ -163,6 +155,8 @@
#LOG(LOG_INFO, __name__, 'Activate pppd returned', r)
finally:
self.cpid = -1
+ system('ifdown usb0')
+ system('ifup usb0')
except Exception, e:
LOG(LOG_ERR, __name__, 'Activate', e)
More information about the Smartphones-commits
mailing list