×

Discussion Board

Results 1 to 6 of 6
  1. #1
    Registered User
    Join Date
    Nov 2007
    Posts
    10

    position_stop() problem

    So I want to get GPS data.

    There is method called position_stop() which should (according to PythonForS60_1_4_2.pdf) Stop an ongoing position request.

    I want stop GPS retrieving after 10 seconds so basically I need to know a way to stop GPS retrieving.

    But when I run stop_position() my program will just quit (even quit Python program).

    import positioning

    def cb(event):
    global GData
    GData = event
    #gps() will store gps data
    gps()
    positioning.stop_position()

    def getGPS():
    positioning.select_module(270526858)
    positioning.set_requestors([{"type":"service","format":"application","data":"test_app"}])
    positioning.position(course=0,satellites=0, callback=cb, interval=10000000, partial = 1)

  2. #2
    Regular Contributor
    Join Date
    Jan 2004
    Location
    Helsinki
    Posts
    376

    Re: position_stop() problem

    Quote Originally Posted by JereKuusela View Post
    So I want to get GPS data.

    There is method called position_stop() which should (according to PythonForS60_1_4_2.pdf) Stop an ongoing position request.

    I want stop GPS retrieving after 10 seconds so basically I need to know a way to stop GPS retrieving.

    But when I run stop_position() my program will just quit (even quit Python program).
    stop_position() must be called in the main thread and not in 1) callback 2) any other thread.
    Mikko Ohtamaa

    http://mfabrik.com
    http://blog.mfabrik.com

  3. #3
    Registered User
    Join Date
    Nov 2007
    Posts
    10

    Re: position_stop() problem

    Ok, thanks for the clarification.

  4. #4
    Registered User
    Join Date
    Mar 2009
    Posts
    3

    Re: position_stop() problem

    I want a function that tries for 1 minute to get a valid GPS data and than stop GPS. But this has to run in a thread (application might not stop for 1 minute). It seems that gps callback and thread do not work well together. Any ideas?

  5. #5
    Registered User
    Join Date
    Feb 2009
    Posts
    40

    Question Re: position_stop() problem

    Quote Originally Posted by miohtama View Post
    stop_position() must be called in the main thread and not in 1) callback 2) any other thread.
    Is this how it's gonna be in the future too? Because I'd like to use positioning in a multi-threaded application.

  6. #6
    Regular Contributor
    Join Date
    Mar 2003
    Location
    UK
    Posts
    125

    Re: position_stop() problem

    Quote Originally Posted by gtannus View Post
    I want a function that tries for 1 minute to get a valid GPS data and than stop GPS. But this has to run in a thread (application might not stop for 1 minute). It seems that gps callback and thread do not work well together. Any ideas?
    The general structure of a PyS60 program seems to be:

    1. Set everything up
    2. Wait on an e32.Ao_lock()
    3. Process events from other active objects, until you want to quit
    4. Signal the lock, and exit

    Point is that most of the time, you're at step 3, so as long as none of your event handlers block the main thread, you can do virtually everything in a single thread.

    According to the docs, if you use a callback, positioning.position() won't block the thread, so why d'ya need another thread?

    I can't test this, cos I'm too lazy to resign PythonScriptShell with permission to use positioning, but...

    Code:
    import e32, positioning
    
    lock = e32.Ao_lock()
    data = None
    timer = e32.Ao_timer()
    
    def stopApp():
        lock.signal()
    
    def startSearch():
        positioning.position(<insert other params here>, callback=searchCallback)
        timer.after(60, stopSearch)
    
    def stopSearch():
        positioning.stop_position()
    
    def searchCallback(d):
        if dataIsValid(d):
            timer.cancel()
            global data
            data = d
            stopSearch()
            # Do other stuff here
    
    def dataIsValid(d):
        # I guess it's up to you to decide when you have enough info
        if <insert condition here>:
            return True
        else:
            return False
    
    # Setup app here
    
    lock.wait()
    As a general rule, most IO functions have a non-blocking option. The only time you really need another thread is when you're CPU-bound (e.g. doing some serious number-crunching) for longer than you're prepared to let the UI be unresponsive for (maybe 100ms or so).

    Now, having said all that, if point #1 in the following is true, which I can't confirm...

    Quote Originally Posted by miohtama View Post
    stop_position() must be called in the main thread and not in 1) callback 2) any other thread.
    ...then you'll have to do something more complicated, like either wrapping the start/stop positioning method in an e32.ao_callgate(), or if that doesn't work, you'll have to replace the Ao_lock() with something like...

    Code:
    import e32, positioning
    
    running = True
    data = None
    timer = e32.Ao_timer()
    callQueue = []
    
    def stopApp():
        global running
        running = False
    
    def callInMainAo(func, args = (), kwargs = {}):
        callQueue.append((func, args, kwargs))
    
    def startSearch():
        callInMainAo(positioning.position, (<insert other params here>), {'callback': searchCallback})
        timer.after(60, stopSearch)
    
    def stopSearch():
        callInMainAo(positioning.stop_position)
    
    def searchCallback(d):
        if dataIsValid(d):
            timer.cancel()
            global data
            data = d
            stopSearch()
            # Do other stuff here
    
    def dataIsValid(d):
        # I guess it's up to you to decide when you have enough info
        if <insert condition here>:
            return True
        else:
            return False
    
    # Setup app here
    
    while running:
        if not callQueue:
            e32.ao_sleep(0.1)
            continue
        while callQueue:
            func, args, kwargs = calls.pop(0)
            apply(func, args, kwargs)
    Just make sure you don't push a blocking call onto the call queue.

Similar Threads

  1. Problem with eglSwapBuffers and heap corruption
    By greatape in forum Symbian Media (Closed)
    Replies: 2
    Last Post: 2007-05-24, 03:35
  2. netcards - Problem with opening adapter
    By kernj in forum Symbian Tools & SDKs
    Replies: 5
    Last Post: 2007-01-10, 08:56
  3. WAP service problem on Apache
    By bigg_o in forum Browsing and Mark-ups
    Replies: 3
    Last Post: 2005-04-17, 16:05
  4. Problem: S60 SDK for CW in PC with .NET
    By anttij in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2005-02-28, 11:36

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×