显示标签为“s60”的博文。显示所有博文
显示标签为“s60”的博文。显示所有博文

2008/08/08

gps and gsm locations from python s60

没有评论:
Goal: periodically obtain 1) BT GPS (i.e. $GPRMC and $GPGGA sentences) and 2) GSM cell id at the same time and save.

____________________________________

# Simple BT App
#$GPRMC,161229.487,A,3723.2475,N,12158.3416,W,0.13,309.62,120598, ,*10

import socket,location,urllib

class BTReader:

def connect(self):
self.sock=socket.socket(socket.AF_BT,socket.SOCK_STREAM)
address,services=socket.bt_discover()
print "Discovered: %s, %s"%(address,services)
target=(address,services.values()[0])
print "Connecting to "+str(target)
self.sock.connect(target)

def readposition(self):
try:
buffer=""
ch = self.sock.recv(1)
while(ch !='\n'):
buffer+=ch
ch = self.sock.recv(1)
# print buffer

if (buffer[0:6]=="$GPRMC"):
(GPRMC,utc,status,lat,latns,lon,lonew,knots,course,date,xx1,xx2)=buffer.split(",")
return "GPS (%s,%s,%s,%s,%s)"%(utc,lat+latns,lon+lonew,knots,course)
except Error:
return "Error!\n"
return ""

def close(self):
self.sock.close()

class GSM_loc:

def upd(self):
self.loc = location.gsm_location()
return "GSM (MCC:%s MNC:%s LAC:%s CID=%s)"%(self.loc[0], self.loc[1], self.loc[2], self.loc[3])

gsm = GSM_loc()

bt=BTReader()
bt.connect()

i=0
while (i<15):
print gsm.upd()
print bt.readposition()
i+=1

bt.close()

在nokia s60手机上编写 python 程序

没有评论:

s60: 为symbian os 的手机操作系统.这种可编程的手机通常称智能手机,如我的手机nokia 7610
PyS60:Python for S60

手机上安装 PyS60

下载点 http://sourceforge.net/projects/pys60/%E4%B8%8B%E8%BD%BD
* PythonForS60_1_3_20_2ndEd.SIS - PyS60
* PythonScriptShell_1_3_20_2ndEd.SIS - Python shell 否则没有运行界面

开发环境的选取

方法1。在windows里面写python程序。保存,手机拔卡,用读卡器把程序放到卡里,手机插卡,然后运行python for s60 然后运行脚本。调试起来比较麻烦。也可用bluetooth console传数据。

Q:Symbian python程序是否可以制作成独立软件包(sis)?
A:可以,使用Symbian Python SDK里面带的py2sis.exe.
用法:

py2sis.exe python程序名.py sis文件名称.sis --uid=0x12345678
例子:

E:\Nokia\Tools\Python_for_Series_60\py2sis>py2sis.exe sms.py smskiki.sis --uid=0x100039Cf
注意:目标文件名一定要添加sis后缀,不然会出现error: invalid destination file

方法2。安装nokia的sdk,这样就构造了一个模拟器,然后从模拟器里面安装python。
PythonForS60_1_3_20_SDK_2ndEd.SIS - SDK 开发环境,可不装,用 wxpython+pys60 emulation开发

方法3。wxPython 模拟器 (推荐
和nokia sdk模拟器不同的是,PyS60 emulation library利用wxPython gtk只写了主要两个图形包例如appuifw,e32。appuifw继承了wx的图形类。

software:
* python2.4 当然需要 (from http://www.python.org/ftp/python/2.4.3/python-2.4.3.msi)
* PyS60 emulation library (4 files: "appuifw.py, e32.py, graphics.py, key_codes.py")
* wxPython (for win32 or linux, www.wxpython.org )

windows 下安装
安装办法:先去下载python 2.4,然后再去下载wxPython。然后下这个模拟器,把里面的四个py文件放到C:\Python2.4\Lib下。(具体放到哪里得看你的Python的安装目录了)

Ubuntu 下安装
- wxPython
(copied from http://wxpython.org/download.php#binaries)
Add the following to your /etc/apt/sources.list file:

# wxPython APT repository at wxcommunity.com
deb http://wxpython.wxcommunity.com/apt/ubuntu/dapper /
deb-src http://wxpython.wxcommunity.com/apt/ubuntu/dapper /

After the repository info has been added to /etc/apt/sources.list you can fetch and install the packages using one of the GUI package manager tools such as Synaptic or Adept, or by running the following commands from a terminal window:

sudo apt-get update
sudo apt-get install python-wxgtk2.8 python-wxtools wx2.8-i18n

- pys60 compact library
put 4 files to PYTHONPATH directory, which is normally /usr/lib/python2.x. Show PYTHONPATH in "import sys, print sys.path".

手机与电脑之间的文件传输、控制

方法1:蓝牙控制台

能够让你通过个人电脑连接你手机上的Python命令行并执行命令。

  1. 在你的PC上打开比如一个超级中端(确定你已经安装了蓝牙设备并为超级终端选择了正确的端口)。
  2. 在你的手机上运行python -> optoins -> Bluetooth console。现在一个蓝牙连接将会被激活,python命令行将会显示在超级终端上

方法2。MIT PUTools: 使用bluetooth 在手机和pc之间传数据,实现同步。可以在PC上编程序,然后整个传到手机上去run over bluetooth。网址是http://people.csail.mit.edu/kapu/symbian/python.html

一个显示输入对话框的程序

import appuifw
import e32

def bexit():
app_lock.signal()
def addtext():
t = appuifw.query(u'Input text:','text')
r.add(unicode(t))
r = appuifw.Text()
r.set(u'info:\n')
appuifw.app.screen = 'normal'
appuifw.app.menu = [(u'Add',addtext),(u'Exit',bexit)]
appuifw.app.body = r
appuifw.app.exit_key_handler = bexit
app_lock = e32.Ao_lock()
app_lock.wait()

保存成1.py然后直接用python执行。。。

sample2: take photo and save

import camera
import graphics
img=camera.take_photo()
img.save("test.jpg")

Note: 如果有gps receiver with bluetooth, 可以在拍照的同时记录下照片经纬度