×

Discussion Board

Results 1 to 8 of 8
  1. #1
    Registered User
    Join Date
    Jul 2004
    Posts
    4

    necessary/possible to flush BT buffer?

    Hi--I'm a newbie to both Python and Series 60 development, so pardon me if this is a stupid question.

    I'm working on a Bluetooth GPS application, and would like to receive location updates from the GPS at least 3 times a minute, if not more often. In my experimentation so far, it seems like the position that my Python script is displaying is lagging far behind my actual current position.

    I'm wondering if the GPS is continually sending to the phone, and the phone is building up a larger and larger buffer, so that the position I display is increasingly out of date.

    When using socket.recv(), does the phone buffer all incoming data? If so, is there any way that I can flush the buffer and get the newest data coming in through the socket, so that I don't end up with out-of-date locations?

    I'm developing on a 6620 running the initial release of Python for Series 60.

    Thanks for any help.

  2. #2
    Registered User
    Join Date
    Jul 2004
    Posts
    4
    any thoughts? anybody?

  3. #3
    Registered User
    Join Date
    Mar 2005
    Posts
    4
    I'm puzzled at this problem, and today I see there is an KSockWriteUrgent option at the RSocket::Send() function. Perhaps this will work, I guess it only from its literal mean.

  4. #4
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    How much do you recv at a time? Are you sure you are recving all the data that is in the buffer? It would help if you posted your script here.

  5. #5
    Registered User
    Join Date
    Mar 2005
    Posts
    4
    I'm sorry that I'm using C++ as the develop language, I just use simply the recv function that I could get all the data. But it seems that the data is buffered first and so there is a delay.

  6. #6
    Super Contributor
    Join Date
    Dec 2004
    Posts
    643
    Originally posted by lsqbank
    I'm sorry that I'm using C++ as the develop language, I just use simply the recv function that I could get all the data. But it seems that the data is buffered first and so there is a delay.
    What, you're using C++? I'm not sure if I understand you here, but if you use C++ then why do you ask in a Python forum?

  7. #7
    Registered User
    Join Date
    Jul 2004
    Posts
    4
    lsqbank was not the original poster--I think he stumbled into this thread by accident.

    The method that reads the position from the BT GPS is as follows--this is adapted from code found on this forum as well as GPSWanderer's gmap.py.

    Code:
        def readposition(self):
            haveFix=0
            latitude_in=0
            longitude_in=0
            while 1:
                try:
                    buffer=""
                    ch=self.sock.recv(1)
                    while(ch!='$'):
                        ch=self.sock.recv(1)
                    while 1:
                        if (ch=='\r'):
                            break
                        buffer+=ch
                        ch=self.sock.recv(1)
                    if (buffer[0:6]=="$GPGGA"):
                        try:
                            (GPGGA,utcTime,lat,ns,lon,ew,posfix,sats,hdop,alt,altunits,sep,sepunits,age,sid)=buffer.split(",")
                            latitude_in=float(lat)
                            longitude_in=float(lon)
                            haveFix=int(posfix)
                        except:
                            appuifw.note(u'No data from GPS.','info')
                            haveFix=0
    
                        #if (haveFix and (hdop < 4)):
                        if haveFix:
                            #fix_message = u'Fix obtained, POSFIX=%s, HDOP=%s.' % (posfix,hdop)
                            #appuifw.note(fix_message,'info')
                            if ns == 'S':
                                latitude_in = -latitude_in
                            if ew == 'W':
                                longitude_in = -longitude_in
    
                            latitude_degrees = int(latitude_in/100)
                            latitude_minutes = latitude_in - latitude_degrees*100
    
                            longitude_degrees = int(longitude_in/100)
                            longitude_minutes = longitude_in - longitude_degrees*100
    
                            latitude = latitude_degrees + (latitude_minutes/60)
                            longitude = longitude_degrees + (longitude_minutes/60)
    
                            print (latitude, longitude, hdop)
                            return (latitude, longitude, hdop)
    
                        no_fix_message = u'No fix. POSFIX=%s, HDOP=%s.' % (posfix, hdop)
                        #appuifw.note(no_fix_message,'info')
                        print no_fix_message
                        return None
                            
                except Exception:
                    return None

  8. #8
    Registered User
    Join Date
    Jul 2004
    Posts
    4

    problem solved

    Ok, I got it. I added a recv(8192) before I cleared my buffer variable, and that did the trick. I just didn't understand how sockets work.

    Thanks much.

Posting Permissions

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