Home | History | Annotate | Download | only in hardware_GobiGPS
      1 # Copyright (c) 2010 The Chromium OS Authors. All rights reserved.
      2 # Use of this source code is governed by a BSD-style license that can be
      3 # found in the LICENSE file.
      4 
      5 
      6 #
      7 # This test is overly simple right now, it'll just make sure that there are
      8 # at least a few satellites seen (i.e. that signal can be received by the GPS).
      9 #
     10 # There are no checks to make sure that a fix can be had, nor of the precision
     11 # or accurracy of said fix. That can either be handled by higher-level tests
     12 # or added here later.
     13 #
     14 
     15 
     16 import logging, re
     17 from autotest_lib.client.bin import test
     18 from autotest_lib.client.common_lib import error, utils
     19 
     20 
     21 class hardware_GobiGPS(test.test):
     22     version = 1
     23 
     24     def run_once(self):
     25         sats_seen = {}
     26         sats_signal = {}
     27         got_fix = False
     28         pos_lat = ""
     29         pos_long = ""
     30 
     31         try:
     32             nmea = utils.system_output('head -300 /tmp/gobi-nmea', timeout=60)
     33         except:
     34             raise error.TestFail('GPS access failed')
     35             return
     36 
     37         logging.debug(nmea)
     38         for line in nmea.split('\n'):
     39             line = line.strip()
     40 
     41             # Satellites in view
     42             if line.startswith('$GPGSV'):
     43                 line = line.rstrip('*0123456789ABCDEF')
     44                 fields = line.split(',')[4:]
     45                 while fields:
     46                     sat = fields[0]
     47                     if fields[3]:
     48                         sats_seen[sat] = True
     49                         sats_signal[sat] = fields[3]
     50                     else:
     51                         sats_seen[sat] = True
     52                     fields = fields[4:]
     53 
     54             # Recommended minimum specific GPS/Transit data
     55             if line.startswith('$GPRMC'):
     56                 # Looks like Gobi has non-standard GPRMC with 13 fields, not 12.
     57                 match = re.search(
     58                     r'^\$GPRMC\,(.*)\,(.*)\,(.*)\,(.*)\,(.*)\,(.*)\,(.*)\,'
     59                     r'(.*)\,(.*)\,(.*)\,(.*),(.*)\*(.*)$',
     60                     line)
     61 
     62                 if match and match.group(2) == 'A' and not got_fix:
     63                     logging.debug('Got fix:')
     64                     logging.debug('Time = %s', match.group(1))
     65                     logging.debug('Status = %s', match.group(2))
     66                     logging.debug('Latitude = %s %s', match.group(3),
     67                                   match.group(4))
     68                     logging.debug('Longitude = %s %s', match.group(5),
     69                                   match.group(6))
     70                     logging.debug('Speed = %s', match.group(7))
     71                     logging.debug('Track Angle = %s', match.group(8))
     72                     logging.debug('Date = %s', match.group(9))
     73                     logging.debug('Magnetic Variation = %s %s', match.group(10),
     74                                   match.group(11))
     75                     got_fix = True
     76                     pos_lat = '%s%s' % (match.group(3), match.group(4))
     77                     pos_long = '%s%s' % (match.group(5), match.group(6))
     78                     break
     79 
     80         logging.debug('number of satellites seen %d: %s',
     81                        len(sats_seen), sats_seen)
     82         logging.debug('number of satellites seen with signal strength %d: %s',
     83                        len(sats_signal), sats_signal)
     84 
     85         if got_fix:
     86             logging.info('Got fix: %s %s' % (pos_lat, pos_long))
     87             return
     88 
     89         # Somewhat random criteria: Pass if you can see 5 at all, and at least 2
     90         # enough to get a signal reading
     91         if len(sats_signal) < 2 and len(sats_seen) < 5:
     92             raise error.TestFail('Unable to find GPS signal')
     93         else:
     94             logging.info('Saw %d GPS satellites, %d with signal strength',
     95                          len(sats_seen), len(sats_signal))
     96