Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for ATT GPSD message #32

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 57 additions & 1 deletion DOCS.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ Description and information copied from [http://catb.org/gpsd/gpsd_json.html](ht
- *Description:* Climb (positive) or sink (negative) rate, meters per second
- *Availability:* mode >= 3
- *Data Type:* float
- **heading**
- *Description:* Heading, degrees from true north
- *Availability:* Always *(**NOTE:** None if attitude is unavailable)*
- *Data Type:* float
- **pitch**
- *Description:* Pitch, degrees
- *Availability:* Always *(**NOTE:** None if attitude is unavailable)*
- *Data Type:* float
- **roll**
- *Description:* Roll, degrees
- *Availability:* Always *(**NOTE:** None if attitude is unavailable)*
- *Data Type:* float

### Methods ###
- **position**
Expand Down Expand Up @@ -107,7 +119,21 @@ Description and information copied from [http://catb.org/gpsd/gpsd_json.html](ht
- *Availability:* mode >= 3
- *Parameters:* None
- *Return Type:* float

- **heading**
- *Description:* Heading, degrees from true north
- *Availability:* Always *(**NOTE:** None if attitude is unavailable)*
- *Parameters:* None
- *Data Type:* float
- **pitch**
- *Description:* Pitch, degrees
- *Availability:* Always *(**NOTE:** None if attitude is unavailable)*
- *Parameters:* None
- *Data Type:* float
- **roll**
- *Description:* Roll, degrees
- *Availability:* Always *(**NOTE:** None if attitude is unavailable)*
- *Parameters:* None
- *Data Type:* float

Exception Information
-----
Expand Down Expand Up @@ -184,6 +210,21 @@ else:
print(" Altitude: NOT AVAILABLE")
print(" Climb: NOT AVAILABLE")

if (packet.heading is not None):
print(" Heading: " + str(packet.heading))
else:
print(" Heading: NOT AVAILABLE")

if (packet.pitch is not None):
print(" Pitch: " + str(packet.pitch))
else:
print(" Pitch: NOT AVAILABLE")

if (packet.roll is not None):
print(" Roll: " + str(packet.roll))
else:
print(" Roll: NOT AVAILABLE")

print(" ************** METHODS ************** ")
if packet.mode >= 2:
print(" Location: " + str(packet.position()))
Expand All @@ -209,6 +250,21 @@ print(" Altitude: NOT AVAILABLE")
# print(" Movement: NOT AVAILABLE")
# print(" Speed Vertical: NOT AVAILABLE")

if (packet.heading is not None):
print(" Heading: " + str(packet.heading()))
else:
print(" Heading: NOT AVAILABLE")

if (packet.pitch is not None):
print(" Pitch: " + str(packet.pitch()))
else:
print(" Pitch: NOT AVAILABLE")

if (packet.roll is not None):
print(" Roll: " + str(packet.roll()))
else:
print(" Roll: NOT AVAILABLE")

print(" ************* FUNCTIONS ************* ")
print("Device: " + str(gpsd.device()))
```
Expand Down
47 changes: 47 additions & 0 deletions gpsd/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,9 @@ class GpsResponse(object):
:type climb: float
:type time: str
:type error: dict[str, float]
:type heading: float
:type pitch: float
:type roll: float

:var self.mode: Indicates the status of the GPS reception, 0=No value, 1=No fix, 2=2D fix, 3=3D fix
:var self.sats: The number of satellites received by the GPS unit
Expand All @@ -56,6 +59,9 @@ class GpsResponse(object):
:var self.climb: Climb (positive) or sink (negative) rate, meters per second
:var self.time: Time/date stamp in ISO8601 format, UTC. May have a fractional part of up to .001sec precision.
:var self.error: GPSD error margin information
:var self.heading: heading, degrees from true north.
:var self.pitch: pitch in degrees.
:var self.roll: roll in degrees.

GPSD error margin information
-----------------------------
Expand Down Expand Up @@ -83,6 +89,9 @@ def __init__(self):
self.climb = 0
self.time = ''
self.error = {}
self.heading = None
self.pitch = None
self.roll = None

@classmethod
def from_json(cls, packet):
Expand All @@ -96,6 +105,7 @@ def from_json(cls, packet):
raise UserWarning('GPS not active')
last_tpv = packet['tpv'][-1]
last_sky = packet['sky'][-1]
last_att = packet['att'][-1]

if 'satellites' in last_sky:
result.sats = len(last_sky['satellites'])
Expand Down Expand Up @@ -128,6 +138,10 @@ def from_json(cls, packet):
result.error['c'] = last_tpv['epc'] if 'epc' in last_tpv else 0
result.error['v'] = last_tpv['epv'] if 'epv' in last_tpv else 0

result.heading = last_att['heading'] if 'heading' in last_att else None
result.pitch = last_att['pitch'] if 'pitch' in last_att else None
result.roll = last_att['roll'] if 'roll' in last_att else None

return result

def position(self):
Expand Down Expand Up @@ -228,6 +242,39 @@ def get_time(self, local_time=False):

return time

def heading(self):
""" Get the heading in degrees from true north.

GPSD provides vehicle attitude reports for selective gyroscope
and digital compass sensors. If the sensor does not support
vehicle attitude reports, then this method will return None.

:return: float
"""
return self.heading

def pitch(self):
""" Get the pitch in degrees.

GPSD provides vehicle attitude reports for selective gyroscope
and digital compass sensors. If the sensor does not support
vehicle attitude reports, then this method will return None.

:return: float
"""
return self.pitch

def roll(self):
""" Get the roll in degrees.

GPSD provides vehicle attitude reports for selective gyroscope
and digital compass sensors. If the sensor does not support
vehicle attitude reports, then this method will return None.

:return: float
"""
return self.roll

def __repr__(self):
modes = {
0: 'No mode',
Expand Down