twisted.positioning.nmea.NMEAAdapter(object)
class documentationtwisted.positioning.nmea
View Source
(View In Hierarchy)
Implements interfaces: twisted.positioning.ipositioning.INMEAReceiver
An adapter from NMEAProtocol receivers to positioning receivers.
Instance Variable | yearThreshold | The earliest possible year that data will be interpreted as. For example,
if this value is 1990 , an NMEA 0183 two-digit year of
"96" will be interpreted as 1996, and a two-digit year of
"13" will be interpreted as 2013. (type: int ) |
Method | __init__ | Initializes a new NMEA adapter. |
Method | clear | Resets this adapter. |
Method | sentenceReceived | Called when a sentence is received. |
Class Variable | _STATEFUL_UPDATE | Information on how to update partial information in the sentence data or
internal adapter state. For more information, see
_statefulUpdate 's docstring. (type: See _statefulUpdate 's docstring) |
Class Variable | _ACCEPTABLE_UNITS | A set of NMEA notations of units that are already acceptable (metric), and
therefore don't need to be converted. (type: frozenset of bytestrings) |
Class Variable | _UNIT_CONVERTERS | Mapping of NMEA notations of units that are not acceptable (not metric) to
converters that take a quantity in that unit and produce a metric quantity. (type: dict of bytestrings to unary callables) |
Class Variable | _SPECIFIC_SENTENCE_FIXES | A mapping of sentece types to specific fixes that are required to extract
useful information from data from those sentences. (type: dict of sentence types to callables that take self and modify
it in-place) |
Class Variable | _FIXERS | Set of unary callables that take an NMEAAdapter instance and extract useful
data from the sentence data, usually modifying the adapter's sentence data
in-place. (type: dict of native strings to unary callables) |
Instance Variable | _state | The current internal state of the receiver. (type: dict ) |
Instance Variable | _sentenceData | The data present in the sentence currently being processed. Starts empty,
is filled as the sentence is parsed. (type: dict ) |
Instance Variable | _receiver | The positioning receiver that will receive parsed data. (type: ipositioning.IPositioningReceiver ) |
Method | _fixTimestamp | Turns the NMEAProtocol timestamp notation into a datetime.time object. The time in this object is expressed as Zulu time. |
Method | _fixDatestamp | Turns an NMEA datestamp format into a datetime.date
object. |
Method | _fixCoordinateFloat | Turns the NMEAProtocol coordinate format into Python float. |
Method | _fixHemisphereSign | Fixes the sign for a hemisphere. |
Method | _getHemisphereSign | Returns the hemisphere sign for a given coordinate type. |
Method | _convert | A simple conversion fix. |
Method | _statefulUpdate | Does a stateful update of a particular positioning attribute. Specifically, this will mutate an object in the current sentence data. |
Method | _fixUnits | Fixes the units of a certain value. If the units are already acceptable (metric), does nothing. |
Method | _fixGSV | Parses partial visible satellite information from a GSV sentence. |
Method | _fixGSA | Extracts the information regarding which satellites were used in obtaining the GPS fix from a GSA sentence. |
Method | _sentenceSpecificFix | Executes a fix for a specific type of sentence. |
Method | _validateCurrentSentence | Tests if a sentence contains a valid fix. |
Method | _cleanCurrentSentence | Cleans the current sentence. |
Method | _updateState | Updates the current state with the new information from the sentence. |
Method | _updateBeaconInformation | Updates existing beacon information state with new data. |
Method | _updateUsedBeacons | Searches the adapter state and sentence data for information about which beacons where used, then adds it to the provided beacon information object. |
Method | _mergeBeaconInformation | Merges beacon information in the adapter state (if it exists) into the provided beacon information. Specifically, this merges used and seen beacons. |
Method | _combineDateAndTime | No summary |
Method | _fireSentenceCallbacks | Fires sentence callbacks for the current sentence. |
_statefulUpdate
's docstring. (type: See _statefulUpdate
's docstring)
frozenset
of bytestrings)
dict
of bytestrings to unary callables)
dict
of sentence types to callables that take self and modify
it in-place)
dict
of native strings to unary callables)
1990
, an NMEA 0183 two-digit year of
"96" will be interpreted as 1996, and a two-digit year of
"13" will be interpreted as 2013. (type: int
)
dict
)
ipositioning.IPositioningReceiver
)
Initializes a new NMEA adapter.
Parameters | receiver | The receiver for positioning sentences. (type: ipositioning.IPositioningReceiver ) |
Turns the NMEAProtocol timestamp notation into a datetime.time object. The time in this object is expressed as Zulu time.
Turns an NMEA datestamp format into a datetime.date
object.
Raises | ValueError | When the day or month value was invalid, e.g. 32nd day, or 13th month, or 0th day or month. |
Turns the NMEAProtocol coordinate format into Python float.
Parameters | coordinateType | The coordinate type. (type: One of Angles.LATITUDE
or Angles.LONGITUDE .) |
Fixes the sign for a hemisphere.
This method must be called after the magnitude for the thing it determines the sign of has been set. This is done by the following functions:
self.FIXERS['magneticVariation']
self.FIXERS['latitudeFloat']
self.FIXERS['longitudeFloat']
Parameters | coordinateType | Coordinate type. One of Angles.LATITUDE ,
Angles.LONGITUDE
or Angles.VARIATION . |
sentenceDataKey | The key name of the hemisphere sign being fixed in the sentence data. If
unspecified, coordinateType is used. (type: str (unless None )) |
Returns the hemisphere sign for a given coordinate type.
Parameters | coordinateType | The coordinate type to find the hemisphere for. (type: Angles.LATITUDE ,
Angles.LONGITUDE
or Angles.VARIATION .) |
Returns | The sign of that hemisphere (-1 or 1). (type: int ) |
A simple conversion fix.
Parameters | key | The attribute name of the value to fix. (type: native string (Python identifier)) |
converter | The function that converts the value. (type: unary callable) |
Does a stateful update of a particular positioning attribute. Specifically, this will mutate an object in the current sentence data.
Using the sentenceKey
, this will get a tuple containing, in
order, the key name in the current state and sentence data, a factory for
new values, the attribute to update, and a converter from sentence data (in
NMEA notation) to something useful.
If the sentence data doesn't have this data yet, it is grabbed from the state. If that doesn't have anything useful yet either, the factory is called to produce a new, empty object. Either way, the object ends up in the sentence data.
Parameters | sentenceKey | The name of the key in the sentence attributes,
NMEAAdapter._STATEFUL_UPDATE dictionary and the adapter state. (type: str ) |
Fixes the units of a certain value. If the units are already acceptable (metric), does nothing.
None of the keys are allowed to be the empty string.
Parameters | unit | The unit that is being converted from. If unspecified or None ,
asks the current sentence for the unitKey . If that also fails,
raises AttributeError . (type: str ) |
unitKey | The name of the key/attribute under which the unit can be found in the
current sentence. If the unit parameter is set, this parameter
is not used. (type: str ) | |
sourceKey | The name of the key/attribute that contains the current value to be
converted (expressed in units as defined according to the unit
parameter). If unset, will use the same key as the value key. (type: str ) | |
valueKey | The key name in which the data will be stored in the
_sentenceData instance attribute. If unset, attempts to remove
"Units" from the end of the unitKey parameter. If
that fails, raises ValueError . (type: str ) |
Extracts the information regarding which satellites were used in obtaining the GPS fix from a GSA sentence.
Precondition: A GSA sentence was fired. Postcondition: The current
sentence data (self._sentenceData
will contain a set of the
currently used PRNs (under the key _usedPRNs
.
Resets this adapter.
This will empty the adapter state and the current sentence data.
Called when a sentence is received.
Will clean the received NMEAProtocol sentence up, and then update the adapter's state, followed by firing the callbacks.
If the received sentence was invalid, the state will be cleared.
Parameters | sentence | The sentence that is received. (type: NMEASentence ) |
Updates the current state with the new information from the sentence.
Updates existing beacon information state with new data.
Searches the adapter state and sentence data for information about which beacons where used, then adds it to the provided beacon information object.
If no new beacon usage information is available, does nothing.
Parameters | beaconInformation | The beacon information object that beacon usage information will be added
to (if necessary). (type: twisted.positioning.base.BeaconInformation ) |
Merges beacon information in the adapter state (if it exists) into the provided beacon information. Specifically, this merges used and seen beacons.
If the adapter state has no beacon information, does nothing.
Parameters | beaconInformation | The beacon information object that beacon information will be merged into
(if necessary). (type: twisted.positioning.base.BeaconInformation ) |
Combines a datetime.date
object and a
datetime.time
object, collected from one or more NMEA
sentences, into a single datetime.datetime
object suitable for
sending to the IPositioningReceiver
.
Fires sentence callbacks for the current sentence.
A callback will only fire if all of the keys it requires are present in the current state and at least one such field was altered in the current sentence.
The callbacks will only be fired with data from _state
.