×

Discussion Board

Results 1 to 4 of 4
  1. #1
    Registered User
    Join Date
    Nov 2009
    Posts
    12

    Need Help on Pack n Unpack

    Hi List,
    Can some one help me with pack and unpack of structs.I get some problem at runtime.

    (a, b,errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih",result)
    The bove statement in the code gives bellow error
    "unpack Requires a string argument of length 25"




    from httplib import HTTP
    from struct import *
    import location
    import urllib2
    import sysinfo


    latitude = 0
    longitude = 0

    def doLookup(cellId, lac, host = "www.google.com", port = 80):

    from string import replace
    #from struct import unpack
    page = "/glm/mmap"
    http = HTTP(host, port)
    result = None
    errorCode = 0
    content_type, body = encode_request(cellId, lac)
    http.putrequest('POST', page)
    http.putheader('Content-Type', content_type)
    http.putheader('Content-Length', str(len(body)))
    http.endheaders()
    http.send(body)
    errcode, errmsg, headers = http.getreply()
    result = http.file.read()


    # could need some modification to get the answer: here I just need
    # to get the 5 first characters
    if (errcode == 200):
    (a, b,errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih",result)
    latitude = latitude / 1000000.0
    longitude = longitude / 1000000.0
    return latitude, longitude

    def encode_request(cellId, lac):
    #from struct import pack
    content_type = 'application/binary'
    body = pack('>hqh2sh13sh5sh3sBiiihiiiiii', 21, 0, 2, 'in', 13, "Nokia N95 8Gb", 5,"1.3.1", 3, "Web", 27, 0, 0, 3, 0, cellId, lac, 0, 0, 0, 0)
    return content_type, body

    (mcc, mnc, lac, cellId) = location.gsm_location()
    print'IMEI :',sysinfo.imei()
    print "MCC :" + str(mcc)
    print "MNC :" + str(mnc)
    print "LAC :" + str(lac)
    print "CID :" + str(cellId)
    print 'Battery Level : ',sysinfo.battery()
    print 'Signal Strength :',sysinfo.signal_bars()
    (latitude, longitude) = doLookup(cellId, lac, "www.google.com", 80)
    print latitude
    print longitude

  2. #2
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Need Help on Pack n Unpack

    Tulipneo

    Quote Originally Posted by tulipneo View Post
    Can some one help me with pack and unpack of structs.I get some problem at runtime.

    (a, b,errorCode, latitude, longitude, c, d, e) = unpack(">hBiiiiih",result)
    The bove statement in the code gives bellow error
    "unpack Requires a string argument of length 25"
    You need to check your result:

    Code:
    result = http.file.read()
    print len(result)
    Your specification is waiting for 25 bytes (hBiiiiih = short(2)+char(1)+int(4)*5+short(2) = 25)
    but result seems to be smaller.

  3. #3
    Registered User
    Join Date
    Nov 2009
    Posts
    12

    Re: Need Help on Pack n Unpack

    Hi
    I did try to debug the app and found that i dont get correct result from google.
    When i again started to debug i found that (mcc, mnc, lac, cellId) = location.gsm_location() does not work properly.
    I get
    cellId = 118041508 lac = 18007 mnc = 76 mcc = 404
    I should get a 5 didgit cellid but unfortunately i get 9 digit number.
    so when i try to unpack soem thing that google does not return i get error.
    I tried the same with my friend it worked fine.
    I just can not figure out where i m wrong.
    Can any oen suggest where i m wrong.

    Br
    Tulip

  4. #4
    Super Contributor
    Join Date
    Nov 2007
    Location
    Sertaozinho/Brazil
    Posts
    768

    Re: Need Help on Pack n Unpack

    Quote Originally Posted by tulipneo View Post
    cellId = 118041508 lac = 18007 mnc = 76 mcc = 404
    Is that the value for result variable ? I don't think so, right ? Could you put the exact answer here ? It will be easier to help you to decode it.

Similar Threads

  1. Python S60 Emulator
    By NAYSAMBO in forum Symbian
    Replies: 25
    Last Post: 2009-04-08, 10:22
  2. Icons in s60
    By drizzt6 in forum Mobile Java General
    Replies: 5
    Last Post: 2009-03-06, 09:32
  3. Feature pack 1?
    By ttl8me in forum General Development Questions
    Replies: 1
    Last Post: 2008-01-17, 22:18
  4. Carbide c++ and S60 3rd Edition Feature Pack 1 Working
    By jimgilmour1 in forum Carbide.c++ IDE and plug-ins (Closed)
    Replies: 1
    Last Post: 2006-10-18, 20:39
  5. Making Finnish language pack for a MIDlet
    By Morpheus3 in forum Mobile Java General
    Replies: 0
    Last Post: 2003-03-25, 16:43

Posting Permissions

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