forked from NTIA/scos-sensor
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsync_gps.py
More file actions
41 lines (29 loc) · 1.14 KB
/
sync_gps.py
File metadata and controls
41 lines (29 loc) · 1.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
"""Monitor the on-board USRP and touch or remove an indicator file."""
import logging
from hardware import gps_iface
from status.models import GPS_LOCATION_DESCRIPTION, Location
from .base import Action
logger = logging.getLogger(__name__)
class SyncGps(Action):
"""Query the GPS and syncronize time and location."""
def __init__(self, admin_only=True):
super(SyncGps, self).__init__(admin_only=admin_only)
self.gps = gps_iface
def __call__(self, name, tid):
logger.debug("Syncing to GPS")
location = self.gps.get_lat_long()
if location is None:
raise RuntimeError("Unable to synchronize to GPS")
latitude, longitude = location
try:
gps_location = Location.objects.get(gps=True)
gps_location.latitude = latitude
gps_location.longitude = longitude
gps_location.save()
except Location.DoesNotExist:
gps_location = Location.objects.create(
gps=True,
description=GPS_LOCATION_DESCRIPTION,
latitude=latitude,
longitude=longitude,
)