相关文章推荐
魁梧的小刀  ·  Socket.BeginReceive ...·  2 年前    · 
善良的荔枝  ·  C# ...·  2 年前    · 
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

Having found http://www.catb.org/gpsd/client-howto.html I managed to get a bit of python (2.7) code that interprets the TPV class and handles it as desired. So far so good and kudos to the maintainer of that site. I get in trouble when I try to go a bit further and also interpret the SKY 'class', basically to know the number of satellites being used. I am however at a loss at how to decode/interpret the 'SKY' data.

Here is my basic code:

session = gps.gps(mode=gps.WATCH_ENABLE)
    while True:
        report = session.next()
        ( ... )
        if report['class'] == 'SKY':
            print report

and here is sample output, with newlines inserted for readability:

<dictwrapper: {u'gdop': 1.56, u'tdop': 0.66, u'vdop': 1.7, u'hdop': 1.42, u'pdop': 2.22, u'satellites':
 [<dictwrapper: {u'ss': 23, u'el': 26, u'PRN': 2, u'az': 237, u'used': True}>,
  <dictwrapper: {u'ss': 35, u'el': 55, u'PRN': 5, u'az': 293, u'used': True}>,
  <dictwrapper: {u'ss': 0, u'el': 5, u'PRN': 6, u'az': 197, u'used': False}>,
  <dictwrapper: {u'ss': 25, u'el': 63, u'PRN': 7, u'az': 76, u'used': True}>,
  <dictwrapper: {u'ss': 27, u'el': 27, u'PRN': 9, u'az': 87, u'used': True}>,
  <dictwrapper: {u'ss': 28, u'el': 24, u'PRN': 13, u'az': 267, u'used': True}>,
  <dictwrapper: {u'ss': 10, u'el': 4, u'PRN': 16, u'az': 18, u'used': False}>,
  <dictwrapper: {u'ss': 0, u'el': 3, u'PRN': 23, u'az': 89, u'used': False}>,
  <dictwrapper: {u'ss': 26, u'el': 8, u'PRN': 28, u'az': 151, u'used': True}>,
  <dictwrapper: {u'ss': 26, u'el': 68, u'PRN': 30, u'az': 173, u'used': True}>
  ],u'ydop': 0.56, u'tag': u'GSV', u'xdop': 0.64, u'device': u'/dev/ttyACM0', u'class': u'SKY'}>

What's this "dictwrapper" stuff and how can I parse it? I reckon I want to count the fields with "True" to get the number of satellites being used?

Sometimes, it helps to properly word one's questions, and to look at them from a distance. I was able to resolve my little puzzle as follows:

session = gps.gps(mode=gps.WATCH_ENABLE)
    if report['class'] == 'SKY':
     #must get number of satellites from this one
     NSAT=0
     for SAT in report['satellites']:
      if SAT['used'] == True:
       NSAT += 1 
     print "Number of satellites used:",NSAT
        

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.