[ create a new paste ] login | about

Link: http://codepad.org/YEVlmdA6    [ raw code | fork ]

Ale152 - Python, pasted on Sep 4:
import e32
import time
import appuifw
import location
import telephone
import messaging
import positioning

ACTIVATE_NUMBER = appuifw.query(u'Activation number', 'text', u'+39')
SMS_NUMBER = appuifw.query(u'Sms number', 'text', u'+39')
FONT = ('normal', 20)
coord = {'time': 0,
         'lat': 0.0,
         'lon': 0.0,
         'alt': 0.0,
         'speed': 0.0,
         'sat': u'',
         'gsm': []}
sent = 0

def calling(event):
    global sent
    action = event[0]
    num = event[1]
    if action == telephone.EStatusRinging and num == ACTIVATE_NUMBER:
        if coord['gsm']:
            mcc, mnc, lac, cid = coord['gsm']
        else:
            mcc, mnc, lac, cid = [0, 0, 0, 0]
        date = time.strftime("%a, %d %b %Y %H:%M:%S", time.localtime(coord['time']))
        try:
            msg = []
            msg.append(u'Time:%s' % date)
            msg.append(u'Lat:%s' % coord['lat'])
            msg.append(u'Lon:%s' % coord['lon'])
            msg.append(u'Alt:%s' % coord['alt'])
            msg.append(u'Speed:%dkm/h' % coord['speed'])
            msg.append(u'Sat:%s' % coord['sat'])
            msg.append(u'GSM')
            msg.append(u'MCC:%d' % mcc)
            msg.append(u'MNC:%d' % mnc)
            msg.append(u'LAC:%d' % lac)
            msg.append(u'CID:%d' % cid)
            msg = u'\n'.join(msg)
        except Exception, error:
            appuifw.note(str(error).decode('utf-8'), 'error')
        messaging.sms_send(SMS_NUMBER, msg)
        sent += 1
               
def gps(event):
    global coord
    sat = event['satellites']['satellites']
    u_sat = event['satellites']['used_satellites']
    if u_sat > 2:
        coord['time'] = event['satellites']['time']
        coord['lat'] = event['position']['latitude']
        coord['lon'] = event['position']['longitude']
        coord['alt'] = event['position']['altitude']
        coord['speed'] = event['course']['speed'] * 3.6
        coord['sat'] = u'%d(%d)' % (sat, u_sat)
    else:
        coord['time'] = time.time()
        coord['lat'] = 'NoSatellites!'
        coord['lon'] = 'NoSatellites!'
        coord['alt'] = 'NoSatellites!'
        coord['speed'] = 0
        coord['sat'] = u'%d(%d)' % (sat, u_sat)
    gsm_data = location.gsm_location()
    if gsm_data:
        coord['gsm'] = gsm_data
    if sat:
        txt_sat = u'Satellites: %d(%d)' % (sat, u_sat)
    else:
        txt_sat = u'Satellites: waiting...'
    c.clear()    
    c.text((5, 30), txt_sat, font = FONT)
    c.text((5, 50), u'Requests: %d' % sent, font = FONT)

def quit():
    positioning.stop_position()
    lock.signal()

c = appuifw.Canvas()
appuifw.app.body = c
telephone.call_state(calling)

GPS_MODULE = positioning.default_module() # Default GPS module
REQUEST = {"type":"service", "format":"application", "data":"test_app"}
positioning.select_module(GPS_MODULE)
positioning.set_requestors([REQUEST])
positioning.position(course=1, satellites=1, partial=1, callback=gps) # Starts GPS

lock = e32.Ao_lock()
lock.wait()


Create a new paste based on this one


Comments: