U  W[@sdZddlmZmZddlZddlZddlmZddlm Z m Z ddl m Z m Z mZddlmZddlmZdd lmZmZmZmZGd d d e ZGd d d e ZGddde ZddZddZGdddeejZGdddejZ ee j!Gddde"Z#dddgZ$dS)a Classes for working with NMEA 0183 sentence producing devices. This standard is generally just called "NMEA", which is actually the name of the body that produces the standard, not the standard itself.. For more information, read the blog post on NMEA by ESR (the gpsd maintainer) at U{http://esr.ibiblio.org/?p=801}. Unfortunately, official specifications on NMEA 0183 are only available at a cost. More information can be found on the Wikipedia page: U{https://en.wikipedia.org/wiki/NMEA_0183}. The official standard may be obtained through the NMEA's website: U{http://www.nmea.org/content/nmea_standards/nmea_0183_v_410.asp}. @since: 14.0 )absolute_importdivisionN) implementer)Values ValueConstant)base ipositioning _sentence)Angles) LineReceiver)reduceizip nativeString iterbytesc@s4eZdZdZdZdZdZdZdZdZ dZ d Z d Z d S) GPGGAFixQualitiesav The possible fix quality indications for GPGGA sentences. @cvar INVALID_FIX: The fix is invalid. @cvar GPS_FIX: There is a fix, acquired using GPS. @cvar DGPS_FIX: There is a fix, acquired using differential GPS (DGPS). @cvar PPS_FIX: There is a fix, acquired using the precise positioning service (PPS). @cvar RTK_FIX: There is a fix, acquired using fixed real-time kinematics. This means that there was a sufficient number of shared satellites with the base station, usually yielding a resolution in the centimeter range. This was added in NMEA 0183 version 3.0. This is also called Carrier-Phase Enhancement or CPGPS, particularly when used in combination with GPS. @cvar FLOAT_RTK_FIX: There is a fix, acquired using floating real-time kinematics. The same comments apply as for a fixed real-time kinematics fix, except that there were insufficient shared satellites to acquire it, so instead you got a slightly less good floating fix. Typical resolution in the decimeter range. @cvar DEAD_RECKONING: There is currently no more fix, but this data was computed using a previous fix and some information about motion (either from that fix or from other sources) using simple dead reckoning. Not particularly reliable, but better-than-nonsense data. @cvar MANUAL: There is no real fix from this device, but the location has been manually entered, presumably with data obtained from some other positioning method. @cvar SIMULATED: There is no real fix, but instead it is being simulated. 012345678N) __name__ __module__ __qualname____doc__ INVALID_FIXZGPS_FIXZDGPS_FIXZPPS_FIXZRTK_FIXZ FLOAT_RTK_FIXZDEAD_RECKONINGZMANUALZ SIMULATEDrr:/usr/lib/python3/dist-packages/twisted/positioning/nmea.pyr$src@s eZdZdZedZedZdS)GPGLLGPRMCFixQualitiesa The possible fix quality indications in GPGLL and GPRMC sentences. Unfortunately, these sentences only indicate whether data is good or void. They provide no other information, such as what went wrong if the data is void, or how good the data is if the data is not void. @cvar ACTIVE: The data is okay. @cvar VOID: The data is void, and should not be used. AVN)rrrrrZACTIVEVOIDrrrr r!Ms r!c@s(eZdZdZedZedZedZdS) GPGSAFixTypesa  The possible fix types of a GPGSA sentence. @cvar GSA_NO_FIX: The sentence reports no fix at all. @cvar GSA_2D_FIX: The sentence reports a 2D fix: position but no altitude. @cvar GSA_3D_FIX: The sentence reports a 3D fix: position with altitude. rrrN)rrrrr GSA_NO_FIXZ GSA_2D_FIXZ GSA_3D_FIXrrrr r%]sr%cCsX|dddkr"|dddS|dddkrD|dddStd|fdS) z Returns the split version of an NMEA sentence, minus header and checksum. >>> _split(b"$GPGGA,spam,eggs*00") [b'GPGGA', b'spam', b'eggs'] @param sentence: The NMEA sentence to split. @type sentence: C{bytes} *,Nzmalformed sentence %s)splitrInvalidSentence)sentencerrr _splitks r0cCsh|dddkrdt|ddd|dd}}ttjddt|D}||krdtd ||fdS) a7 Validates the checksum of an NMEA sentence. @param sentence: The NMEA sentence to check the checksum of. @type sentence: C{bytes} @raise ValueError: If the sentence has an invalid checksum. Simply returns on sentences that either don't have a checksum, or have a valid checksum. r'r(r)Nr*cSsg|] }t|qSr)ord.0xrrr sz%_validateChecksum..z %02x != %02x)intr operatorxorrrZInvalidChecksum)r/Z referencesourceZcomputedrrr _validateChecksums  r;c@seZdZdZd@ddZddZddd d d d d dddddddgdddd d d dddddg ddd dddddd d!d"d#d$d%d&d'd(d)d*gdd d d ddgdgdddd d d d+d,d-d.d/g dd0d1d2d3d4d5d6d7d8d9d:d;dgd?ZdS)A NMEAProtocola A protocol that parses and verifies the checksum of an NMEA sentence (in string form, not L{NMEASentence}), and delegates to a receiver. It receives lines and verifies these lines are NMEA sentences. If they are, verifies their checksum and unpacks them into their components. It then wraps them in L{NMEASentence} objects and calls the appropriate receiver method with them. @cvar _SENTENCE_CONTENTS: Has the field names in an NMEA sentence for each sentence type (in order, obviously). @type _SENTENCE_CONTENTS: C{dict} of bytestrings to C{list}s of C{str} @param _receiver: A receiver for NMEAProtocol sentence objects. @type _receiver: L{INMEAReceiver} @param _sentenceCallback: A function that will be called with a new L{NMEASentence} when it is created. Useful for massaging data from particularly misbehaving NMEA receivers. @type _sentenceCallback: unary callable NcCs||_||_dS)a Initializes an NMEAProtocol. @param receiver: A receiver for NMEAProtocol sentence objects. @type receiver: L{INMEAReceiver} @param sentenceCallback: A function that will be called with a new L{NMEASentence} when it is created. Useful for massaging data from particularly misbehaving NMEA receivers. @type sentenceCallback: unary callable N) _receiver_sentenceCallback)selfreceiverZsentenceCallbackrrr __init__s zNMEAProtocol.__init__c Cs|}t|t|}t|d}dd|ddD}z|j|}Wn tk rhtd|YnXd|i}t||D] \}} |dk r|| dkr|| ||<q|t|}|j dk r| ||j |dS) z Parses the data from the sentence and validates the checksum. @param rawSentence: The NMEA positioning sentence. @type rawSentence: C{bytes} rcSsg|] }t|qSr)rr3rrr r6sz-NMEAProtocol.lineReceived..r*Nzunknown sentence type %stype) stripr;r0r_SENTENCE_CONTENTSKeyError ValueErrorr NMEASentencer>r=sentenceReceived) r?Z rawSentencer/Z splitSentenceZ sentenceTypecontentskeysZ sentenceDatakeyvaluerrr lineReceiveds"    zNMEAProtocol.lineReceived timestamp latitudeFloatlatitudeHemispherelongitudeFloatlongitudeHemisphere fixQualityZnumberOfSatellitesSeenhorizontalDilutionOfPrecisionaltitude altitudeUnitsheightOfGeoidAboveWGS84heightOfGeoidAboveWGS84UnitsdataMode speedInKnots trueHeading datestampmagneticVariationmagneticVariationDirectionnumberOfGSVSentencesGSVSentenceIndexZsatellitePRN_0Z elevation_0Z azimuth_0ZsignalToNoiseRatio_0ZsatellitePRN_1Z elevation_1Z azimuth_1ZsignalToNoiseRatio_1ZsatellitePRN_2Z elevation_2Z azimuth_2ZsignalToNoiseRatio_2ZsatellitePRN_3Z elevation_3Z azimuth_3ZsignalToNoiseRatio_3 elevationZnumberOfIterationsZnumberOfDopplerIntervalsZupdateDistanceInNauticalMiles satellitePRNfixTypeZusedSatellitePRN_0ZusedSatellitePRN_1ZusedSatellitePRN_2ZusedSatellitePRN_3ZusedSatellitePRN_4ZusedSatellitePRN_5ZusedSatellitePRN_6ZusedSatellitePRN_7ZusedSatellitePRN_8ZusedSatellitePRN_9ZusedSatellitePRN_10ZusedSatellitePRN_11positionDilutionOfPrecisionverticalDilutionOfPrecision)ZGPGGAZGPRMCGPGSVZGPGLLZGPHDTZGPTRFGPGSA)N)rrrrrArNrErrrr r<s # r<c@s(eZdZdZeZddZddZdS)rHa An object representing an NMEA sentence. The attributes of this objects are raw NMEA protocol data, which are all ASCII bytestrings. This object contains all the raw NMEA protocol data in a single sentence. Not all of these necessarily have to be present in the sentence. Missing attributes are L{None} when accessed. @ivar type: The sentence type (C{"GPGGA"}, C{"GPGSV"}...). @ivar numberOfGSVSentences: The total number of GSV sentences in a sequence. @ivar GSVSentenceIndex: The index of this GSV sentence in the GSV sequence. @ivar timestamp: A timestamp. (C{"123456"} -> 12:34:56Z) @ivar datestamp: A datestamp. (C{"230394"} -> 23 Mar 1994) @ivar latitudeFloat: Latitude value. (for example: C{"1234.567"} -> 12 degrees, 34.567 minutes). @ivar latitudeHemisphere: Latitudinal hemisphere (C{"N"} or C{"S"}). @ivar longitudeFloat: Longitude value. See C{latitudeFloat} for an example. @ivar longitudeHemisphere: Longitudinal hemisphere (C{"E"} or C{"W"}). @ivar altitude: The altitude above mean sea level. @ivar altitudeUnits: Units in which altitude is expressed. (Always C{"M"} for meters.) @ivar heightOfGeoidAboveWGS84: The local height of the geoid above the WGS84 ellipsoid model. @ivar heightOfGeoidAboveWGS84Units: The units in which the height above the geoid is expressed. (Always C{"M"} for meters.) @ivar trueHeading: The true heading. @ivar magneticVariation: The magnetic variation. @ivar magneticVariationDirection: The direction of the magnetic variation. One of C{"E"} or C{"W"}. @ivar speedInKnots: The ground speed, expressed in knots. @ivar fixQuality: The quality of the fix. @type fixQuality: One of L{GPGGAFixQualities}. @ivar dataMode: Signals if the data is usable or not. @type dataMode: One of L{GPGLLGPRMCFixQualities}. @ivar numberOfSatellitesSeen: The number of satellites seen by the receiver. @ivar numberOfSatellitesUsed: The number of satellites used in computing the fix. @ivar horizontalDilutionOfPrecision: The dilution of the precision of the position on a plane tangential to the geoid. (HDOP) @ivar verticalDilutionOfPrecision: As C{horizontalDilutionOfPrecision}, but for a position on a plane perpendicular to the geoid. (VDOP) @ivar positionDilutionOfPrecision: Euclidean norm of HDOP and VDOP. @ivar satellitePRN: The unique identifcation number of a particular satellite. Optionally suffixed with C{_N} if multiple satellites are referenced in a sentence, where C{N in range(4)}. @ivar elevation: The elevation of a satellite in decimal degrees. Optionally suffixed with C{_N}, as with C{satellitePRN}. @ivar azimuth: The azimuth of a satellite in decimal degrees. Optionally suffixed with C{_N}, as with C{satellitePRN}. @ivar signalToNoiseRatio: The SNR of a satellite signal, in decibels. Optionally suffixed with C{_N}, as with C{satellitePRN}. @ivar usedSatellitePRN_N: Where C{int(N) in range(12)}. The PRN of a satellite used in computing the fix. cCs |jdkS)z Tests if this current GSV sentence is the first one in a sequence. @return: C{True} if this is the first GSV sentence. @rtype: C{bool} r)rar?rrr _isFirstGSVSentencesz NMEASentence._isFirstGSVSentencecCs |j|jkS)z Tests if this current GSV sentence is the final one in a sequence. @return: C{True} if this is the last GSV sentence. @rtype: C{bool} )rar`rirrr _isLastGSVSentenceszNMEASentence._isLastGSVSentenceN) rrrrr<ZgetSentenceAttributesZALLOWED_ATTRIBUTESrjrkrrrr rHSs< rHc@seZdZdZddZddZdZddZd d ZdRd d Z ddZ ddZ de j defde j dddfde jdefde jdefde jdefdZddZedgZddd dd!ZdSd"d#Zd$d%Zd&d'Zeed(Zd)d*Zd+dd,dd-dd.dd/dd0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;ddd?Zd@dAZdBdCZdDdEZdFdGZdHdIZ dJdKZ!dLdMZ"dNdOZ#dPdQZ$d S)T NMEAAdaptera An adapter from NMEAProtocol receivers to positioning receivers. @cvar _STATEFUL_UPDATE: Information on how to update partial information in the sentence data or internal adapter state. For more information, see C{_statefulUpdate}'s docstring. @type _STATEFUL_UPDATE: See C{_statefulUpdate}'s docstring @cvar _ACCEPTABLE_UNITS: A set of NMEA notations of units that are already acceptable (metric), and therefore don't need to be converted. @type _ACCEPTABLE_UNITS: C{frozenset} of bytestrings @cvar _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 _UNIT_CONVERTERS: C{dict} of bytestrings to unary callables @cvar _SPECIFIC_SENTENCE_FIXES: A mapping of sentece types to specific fixes that are required to extract useful information from data from those sentences. @type _SPECIFIC_SENTENCE_FIXES: C{dict} of sentence types to callables that take self and modify it in-place @cvar _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 _FIXERS: C{dict} of native strings to unary callables @ivar yearThreshold: The earliest possible year that data will be interpreted as. For example, if this value is C{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 yearThreshold: L{int} @ivar _state: The current internal state of the receiver. @type _state: C{dict} @ivar _sentenceData: The data present in the sentence currently being processed. Starts empty, is filled as the sentence is parsed. @type _sentenceData: C{dict} @ivar _receiver: The positioning receiver that will receive parsed data. @type _receiver: L{ipositioning.IPositioningReceiver} cCsi|_i|_||_dS)z Initializes a new NMEA adapter. @param receiver: The receiver for positioning sentences. @type receiver: L{ipositioning.IPositioningReceiver} N)_state _sentenceDatar=)r?r@rrr rAszNMEAAdapter.__init__cCs2|jjdd}tj|d}||jd<dS)z Turns the NMEAProtocol timestamp notation into a datetime.time object. The time in this object is expressed as Zulu time. .rz%H%M%S_timeN)currentSentencerOr-datetimestrptimetimern)r?rOZ timeObjectrrr _fixTimestampszNMEAAdapter._fixTimestampicCst|jj}tt|dd|dd|ddg\}}}||j|jd7}||jkr\|d7}t||||jd<dS)z Turns an NMEA datestamp format into a C{datetime.date} object. @raise ValueError: When the day or month value was invalid, e.g. 32nd day, or 13th month, or 0th day or month. rd_dateN)rqr]mapr7 yearThresholdrrdatern)r?r}ZdayZmonthZyearrrr _fixDatestamps . zNMEAAdapter._fixDatestampc Cs|tjkrd}nd}t|j|d}|d\}}t|ddtd|dd|f}}||d}t||} | |j |<dS) z Turns the NMEAProtocol coordinate format into Python float. @param coordinateType: The coordinate type. @type coordinateType: One of L{Angles.LATITUDE} or L{Angles.LONGITUDE}. latitude longitudeZFloatroNr(z%s.%s<) r LATITUDEgetattrrqr-r7floatrZ Coordinatern) r?coordinateTypeZcoordinateNameZnmeaCoordinateleftrightZdegreesZminutesangleZ coordinaterrr _fixCoordinateFloats *  zNMEAAdapter._fixCoordinateFloatNcCs&|p|}||}|j||dS)a 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: - C{self.FIXERS['magneticVariation']} - C{self.FIXERS['latitudeFloat']} - C{self.FIXERS['longitudeFloat']} @param coordinateType: Coordinate type. One of L{Angles.LATITUDE}, L{Angles.LONGITUDE} or L{Angles.VARIATION}. @param sentenceDataKey: The key name of the hemisphere sign being fixed in the sentence data. If unspecified, C{coordinateType} is used. @type sentenceDataKey: C{str} (unless L{None}) N)_getHemisphereSignrnZsetSign)r?rZsentenceDataKeyZsignrrr _fixHemisphereSign s zNMEAAdapter._fixHemisphereSigncCsx|tjkrd}n.|tjkr d}n|tjkr0d}ntd|ft|j|}|dkrZdS|dkrfdStd |fd S) aS Returns the hemisphere sign for a given coordinate type. @param coordinateType: The coordinate type to find the hemisphere for. @type coordinateType: L{Angles.LATITUDE}, L{Angles.LONGITUDE} or L{Angles.VARIATION}. @return: The sign of that hemisphere (-1 or 1). @rtype: C{int} rQrSr_zunknown coordinate type %sZNEr*ZSWr,zbad hemisphere/direction: %sN)r r LONGITUDE VARIATIONrGrrqupper)r?rZ hemisphereKeyZ hemisphererrr r$s   zNMEAAdapter._getHemisphereSigncCst|j|}|||j|<dS)a A simple conversion fix. @param key: The attribute name of the value to fix. @type key: native string (Python identifier) @param converter: The function that converts the value. @type converter: unary callable N)rrqrn)r?rL converter currentValuerrr _convertAs zNMEAAdapter._convertheadingZ_angleZ variationcCstt|tjSN)rZAnglerr r)rrrr TzNMEAAdapter.Z positionErrorZhdopZvdopZpdop)r\r^rUrfrecCsx|j|\}}}}||jkrRz|j||j|<Wn tk rP||j|<YnX|t|j|}t|j|||dS)a Does a stateful update of a particular positioning attribute. Specifically, this will mutate an object in the current sentence data. Using the C{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. @param sentenceKey: The name of the key in the sentence attributes, C{NMEAAdapter._STATEFUL_UPDATE} dictionary and the adapter state. @type sentenceKey: C{str} N)_STATEFUL_UPDATErnrmrFrrqsetattr)r?Z sentenceKeyrLfactoryattrrZnewValuerrr _statefulUpdate`s zNMEAAdapter._statefulUpdateMcCstt|tjSr)rSpeedrZ MPS_PER_KNOT)ZinKnotsrrr rrcCstt|tjSr)rrrZ MPS_PER_KPH)ZinKPHrrr rr)NKcCs|dkrt|j|}|dkrD|dk r<|dr<|dd}ntd|dkrP|}||jkr~|j|}t|j|}|||j|<dS)a 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. @param unit: The unit that is being converted I{from}. If unspecified or L{None}, asks the current sentence for the C{unitKey}. If that also fails, raises C{AttributeError}. @type unit: C{str} @param unitKey: The name of the key/attribute under which the unit can be found in the current sentence. If the C{unit} parameter is set, this parameter is not used. @type unitKey: C{str} @param sourceKey: The name of the key/attribute that contains the current value to be converted (expressed in units as defined according to the C{unit} parameter). If unset, will use the same key as the value key. @type sourceKey: C{str} @param valueKey: The key name in which the data will be stored in the C{_sentenceData} instance attribute. If unset, attempts to remove "Units" from the end of the C{unitKey} parameter. If that fails, raises C{ValueError}. @type valueKey: C{str} NZUnitsz,valueKey unspecified and couldn't be guessed)rrqendswithrG_ACCEPTABLE_UNITS_UNIT_CONVERTERSrn)r?unitKeyvalueKey sourceKeyunitrrrrr _fixUnitss    zNMEAAdapter._fixUnitscs~t}|jd<d}tdD]Zfddfdd|DD\}}}}|dks|dkr\qt||||}|j|qdS) zS Parses partial visible satellite information from a GSV sentence. _partialBeaconInformation)rcazimuthrbZsignalToNoiseRatiorwcsg|]}tj|qSr)rrq)r4rrirr r6sz'NMEAAdapter._fixGSV..c3s|]}d|fVqdS)z%s_%iNrr4rL)indexrr sz&NMEAAdapter._fixGSV..N)rZBeaconInformationrnrangeZ Satellite seenBeaconsadd)r?beaconInformationrKprnrrbZsnrZ satelliter)rr?r _fixGSVs   zNMEAAdapter._fixGSVcCsRt|jd<ddtdDD].}t|j|d}|dk r|jdt|qdS)aQ 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 (C{self._sentenceData} will contain a set of the currently used PRNs (under the key C{_usedPRNs}. _usedPRNscss|]}d|fVqdS)zusedSatellitePRN_%dNrr3rrr rsz&NMEAAdapter._fixGSA.. N)setrnrrrqrr7)r?rLrrrr _fixGSAs zNMEAAdapter._fixGSA)rgrhcCs$|j|jj}|dk r ||dS)zA Executes a fix for a specific type of sentence. N)_SPECIFIC_SENTENCE_FIXESgetrqrB)r?fixerrrr _sentenceSpecificFixsz NMEAAdapter._sentenceSpecificFixcCs|Sr)rrirrr rrcCs|Sr)rurirrr rrcCs|Sr)r~rirrr rrcCs |tjSr)rr rrirrr rrcCs|tjdS)Nr)rr rrirrr rrcCs |tjSr)rr rrirrr rrcCs|tjdS)Nr)rr rrirrr rrcCs|jddddS)NrVcSstt|SrrZAltituderZstrReprrrr rr&NMEAAdapter...rrrirrr rscCs |jddS)NrWrrrirrr rrcCs|jddddS)NrXcSstt|Srrrrrr rrrrrrirrr rscCs |jddS)NrYrrrirrr rscCs |dS)Nr\rrirrr r rcCs |dS)Nr^rrirrr r rcCs|tjdS)Nr)rr rrirrr rscCs|jddddS)NZspeedr[r)rrrrrirrr rscCs |dS)Nrerrirrr rrcCs |dS)NrUrrirrr rrcCs |dS)Nrfrrirrr rr)rBrOr]rPrQrRrSrVrWrXrYr\r^r_r[rerUrfcCsi|_i|_dS)zp Resets this adapter. This will empty the adapter state and the current sentence data. N)rmrnrirrr clear szNMEAAdapter.clearcCsT||_i|_z||Wntjk r>|YnX||dS)aj 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. @param sentence: The sentence that is received. @type sentence: L{NMEASentence} N) rqrn_validateCurrentSentence_cleanCurrentSentencerr.r _updateState_fireSentenceCallbacks)r?r/rrr rI*s  zNMEAAdapter.sentenceReceivedcCs8|jjtjks*|jjtjks*|jjtj kr4t ddS)z; Tests if a sentence contains a valid fix. z bad sentenceN) rqrTrrrZr!r$rdr%r&rr.rirrr rCs   z$NMEAAdapter._validateCurrentSentencecCs4t|jjD]"}|j|d}|dk r ||q dS)z. Cleans the current sentence. N)sortedrqZpresentAttributes_FIXERSr)r?rLrrrr rMsz!NMEAAdapter._cleanCurrentSentencecCs"|||j|jdS)zW Updates the current state with the new information from the sentence. N)_updateBeaconInformation_combineDateAndTimermupdaternrirrr rXszNMEAAdapter._updateStatecCsb|jd}|dkrdS|||||jr^|jsH|jd=|jd}||jd<dS)zJ Updates existing beacon information state with new data. rNr) rnr_updateUsedBeacons_mergeBeaconInformationrqrkrjrmpop)r?newZbirrr ras      z$NMEAAdapter._updateBeaconInformationcCsR|j|jfD]}|d}|dk r q,q dS|jD]}|j|kr2|j|q2dS)a 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. @param beaconInformation: The beacon information object that beacon usage information will be added to (if necessary). @type beaconInformation: L{twisted.positioning.base.BeaconInformation} rN)rmrnrrZ identifier usedBeaconsr)r?rr:ZusedPRNsZbeaconrrr rts    zNMEAAdapter._updateUsedBeaconscCs<|jd}|dkrdSdD]}t||t||qdS)a 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. @param beaconInformation: The beacon information object that beacon information will be merged into (if necessary). @type beaconInformation: L{twisted.positioning.base.BeaconInformation} rN)rr)rmrrr)r?ZnewBeaconInformationoldrrrr rs z#NMEAAdapter._mergeBeaconInformationcs`tfdddDsdSfdddD\}}|dks@|dkrDdStj||}|jd<dS)z Combines a C{datetime.date} object and a C{datetime.time} object, collected from one or more NMEA sentences, into a single C{datetime.datetime} object suitable for sending to the L{IPositioningReceiver}. c3s|]}|jkVqdSr)rn)r4krirr rsz2NMEAAdapter._combineDateAndTime..)rzrpNcs$g|]}j|pj|qSr)rnrrmrrirr r6sz3NMEAAdapter._combineDateAndTime..rt)anyrrZcombinern)r?r}rtZdtrrir rs  zNMEAAdapter._combineDateAndTimec Cstj}|D]p\}}t|j|}i}d}z,|jD] }||jkrDd}|j|||<q2Wntk rnYqYnX|r|f|qdS)a< 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 L{_state}. FTN) rZIPositioningReceiverZnamesAndDescriptionsrr=Z positionalrnrmrF)r?ZifacenamemethodcallbackkwargsZatLeastOnePresentInSentenceZfieldrrr rs     z"NMEAAdapter._fireSentenceCallbacks)N)NNNN)%rrrrrArur|r~rrrrrZHeadingrZ PositionErrorrr frozensetrrrrrrrrrrIrrrrrrrrrrrr rlsx$         + 6    rl)%rZ __future__rrr8rrZzope.interfacerZ constantlyrrZtwisted.positioningrrr Ztwisted.positioning.baser Ztwisted.protocols.basicr Ztwisted.python.compatr r rrrr!r%r0r;Z!_PositioningSentenceProducerMixinr<Z _BaseSentencerHZ INMEAReceiverobjectrl__all__rrrr s6   )AT1