Attempt to reconnect to GPS device.
(self)
| 582 | """ |
| 583 | if lat is None or lon is None: |
| 584 | return False |
| 585 | try: |
| 586 | lat = float(lat) |
| 587 | lon = float(lon) |
| 588 | except (TypeError, ValueError): |
| 589 | return False |
| 590 | # Reject the "no fix yet" sentinel many modules emit (0.0, 0.0 is |
| 591 | # in the Gulf of Guinea — practically never a real wardriving fix). |
| 592 | if lat == 0.0 and lon == 0.0: |
| 593 | return False |
| 594 | now = time.time() |
| 595 | # Prefer a fresh local fix over an external one. Only skip when the |
| 596 | # current state actually came from a local receiver (NMEA/gpsd) — |
| 597 | # otherwise back-to-back external updates would block each other. |
| 598 | if (self._external_source is None |
| 599 | and (self._serial is not None or self._gpsd_sock is not None) |
| 600 | and self.last_update |
| 601 | and (now - self.last_update) < 5 |
| 602 | and self.fix_quality > 0): |
| 603 | return False |
| 604 | with self._lock: |
| 605 | self.latitude = lat |
| 606 | self.longitude = lon |
| 607 | if alt is not None: |
| 608 | try: |
| 609 | self.altitude = float(alt) |
| 610 | except (TypeError, ValueError): |
| 611 | pass |
| 612 | if speed_kmh is not None: |
| 613 | try: |
| 614 | self.speed_kmh = float(speed_kmh) |
| 615 | except (TypeError, ValueError): |
| 616 | pass |
| 617 | if satellites is not None: |
| 618 | try: |
| 619 | self.satellites = int(satellites) |
| 620 | except (TypeError, ValueError): |
| 621 | pass |
| 622 | if hdop is not None: |
| 623 | try: |
| 624 | self.hdop = float(hdop) |
| 625 | except (TypeError, ValueError): |
| 626 | pass |
| 627 | if self.fix_quality <= 0: |
| 628 | self.fix_quality = 1 |
| 629 | self.last_update = now |
no test coverage detected