%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /lib/python3/dist-packages/twisted/positioning/__pycache__/
Upload File :
Create Path :
Current File : //lib/python3/dist-packages/twisted/positioning/__pycache__/nmea.cpython-312.pyc

�

Ϫ�fV���f�dZddlZddlZddlmZddlmZddlmZm	Z	ddl
mZmZm
Z
ddlmZddlmZdd	lmZmZGd
�de	�ZGd�d
e	�ZGd�de	�Zd�Zd�ZGd�deej4�ZGd�dej8�Zee
j<�Gd�d��Zgd�Z y)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
�N)�reduce)�implementer)�
ValueConstant�Values)�	_sentence�base�ipositioning)�Angles)�LineReceiver)�	iterbytes�nativeStringc�4�eZdZdZdZdZdZdZdZdZ	dZ
d	Zd
Zy)�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.
    �0�1�2�3�4�5�6�7�8N)
�__name__�
__module__�__qualname__�__doc__�INVALID_FIX�GPS_FIX�DGPS_FIX�PPS_FIX�RTK_FIX�
FLOAT_RTK_FIX�DEAD_RECKONING�MANUAL�	SIMULATED���:/usr/lib/python3/dist-packages/twisted/positioning/nmea.pyrr%s6���:�K��G��H��G��G��M��N�
�F��Ir'rc�0�eZdZdZed�Zed�Zy)�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.
    �A�VN)rrrrr�ACTIVE�VOIDr&r'r(r*r*Ns��	��3�
�F����Dr'r*c�@�eZdZdZed�Zed�Zed�Zy)�
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_FIX�
GSA_2D_FIX�
GSA_3D_FIXr&r'r(r0r0^s'����s�#�J��s�#�J��s�#�Jr'r0c��|dddk(r|ddjd�S|dddk(r|ddjd�Stjd|����)	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 )�splitr�InvalidSentence)�sentences r(�_splitr>lsg����2��$����"�~�#�#�D�)�)�	�"�#��$�	���"�~�#�#�D�)�)��"�"�%8��
�#C�D�Dr'c	��|dddk(rpt|ddd�|dd}}ttjt	|�D�cgc]
}t|���c}�}||k7rt
j|d�d|d����yycc}w)	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.
    r5r6r7N�r8�02xz != )�intr�operator�xorr�ordr�InvalidChecksum)r=�	reference�source�x�computeds     r(�_validateChecksumrKs�����2��$������
�r�2�H�Q�r�N�6�	��(�,�,��6�9J�(K�A��Q��(K�L���y� ��&�&�(�3��t�I�c�?�'K�L�L�!���(Ks�A:
c�L�eZdZdZd
d�Zd�Zgd�gd�gd�gd�d	ggd
�gd�d�Zy)�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
    Nc� �||_||_y)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)�self�receiver�sentenceCallbacks   r(�__init__zNMEAProtocol.__init__�s��"���!1��r'c���|j�}t|�t|�}t|d�}|ddD�cgc]
}t|���}}	|j|}d|i}t||�D]\}	}
|	��	|
dk7s�|
||	<�t|�}|j�|j|�|jj|�ycc}w#t
$rt
d|z��wxYw)z�
        Parses the data from the sentence and validates the checksum.

        @param rawSentence: The NMEA positioning sentence.
        @type rawSentence: C{bytes}
        rr8Nzunknown sentence type %s�type�)�striprKr>r
�_SENTENCE_CONTENTS�KeyError�
ValueError�zip�NMEASentencerPrO�sentenceReceived)rQ�rawSentencer=�
splitSentence�sentenceTyperI�contents�keys�sentenceData�key�values           r(�lineReceivedzNMEAProtocol.lineReceived�s���$�$�&���(�#��x�(�
�#�M�!�$4�5��-:�1�2�->�?��L��O�?��?�	H��*�*�<�8�D���-���d�H�-�	*�J�C����5�B�;�$)��S�!�	*� ��-���!�!�-��"�"�8�,����'�'��1��#@���	H��7�,�F�G�G�	H�s�C
�C�C')�	timestamp�
latitudeFloat�latitudeHemisphere�longitudeFloat�longitudeHemisphere�
fixQuality�numberOfSatellitesSeen�horizontalDilutionOfPrecision�altitude�
altitudeUnits�heightOfGeoidAboveWGS84�heightOfGeoidAboveWGS84UnitsNN)rh�dataModerirjrkrl�speedInKnots�trueHeading�	datestamp�magneticVariation�magneticVariationDirection)�numberOfGSVSentences�GSVSentenceIndexrn�satellitePRN_0�elevation_0�	azimuth_0�signalToNoiseRatio_0�satellitePRN_1�elevation_1�	azimuth_1�signalToNoiseRatio_1�satellitePRN_2�elevation_2�	azimuth_2�signalToNoiseRatio_2�satellitePRN_3�elevation_3�	azimuth_3�signalToNoiseRatio_3)rirjrkrlrhrtrv)rwrhrirjrkrl�	elevation�numberOfIterations�numberOfDopplerIntervals�updateDistanceInNauticalMiles�satellitePRN)rt�fixType�usedSatellitePRN_0�usedSatellitePRN_1�usedSatellitePRN_2�usedSatellitePRN_3�usedSatellitePRN_4�usedSatellitePRN_5�usedSatellitePRN_6�usedSatellitePRN_7�usedSatellitePRN_8�usedSatellitePRN_9�usedSatellitePRN_10�usedSatellitePRN_11�positionDilutionOfPrecisionro�verticalDilutionOfPrecision)�GPGGA�GPRMC�GPGSV�GPGLL�GPHDT�GPTRF�GPGSA�N)rrrrrTrgrYr&r'r(rMrM�sD���(2�2�B
�"
�
�*
�
�
�
�
�Y_�r'rMc�<�eZdZdZej�Zd�Zd�Zy)r]a�
    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.
    c� �|jdk(S)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)r{�rQs r(�_isFirstGSVSentencez NMEASentence._isFirstGSVSentencews���$�$��+�+r'c�4�|j|jk(S)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}
        )r{rzr�s r(�_isLastGSVSentencezNMEASentence._isLastGSVSentence�s���$�$��(A�(A�A�Ar'N)	rrrrrM�getSentenceAttributes�ALLOWED_ATTRIBUTESr�r�r&r'r(r]r]7s$��;�z&�;�;�=��,�Br'r]c��eZdZdZd�Zd�ZdZd�Zd�ZdLd�Z	d	�Z
d
�Zdejdefdejd
d�fdejdefdejdefdejdefd�Zd�Zedg�Zd�d�d�ZdMd�Zd�Zd�Zeed�Zd�Zidd��d d!��d"d#��d$d%��d&d'��d(d)��d*d+��d,d-��d.d/��d0d1��d2d3��d4d5��d6d7��d8d9��d:d;��d<d=��d>d?��d@dA�i�ZdB�ZdC�ZdD�ZdE�ZdF�ZdG�Z dH�Z!dI�Z"dJ�Z#dK�Z$y)N�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}
    c�.�i|_i|_||_y)z�
        Initializes a new NMEA adapter.

        @param receiver: The receiver for positioning sentences.
        @type receiver: L{ipositioning.IPositioningReceiver}
        N)�_state�
_sentenceDatarO)rQrRs  r(rTzNMEAAdapter.__init__�s��������!��r'c���|jjjd�d}tjj	|d�j�}||jd<y)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)�currentSentencerhr;�datetime�strptime�timer�)rQrh�
timeObjects   r(�
_fixTimestampzNMEAAdapter._fixTimestamp�sV��
�(�(�2�2�8�8��=�a�@�	��&�&�/�/�	�8�D�I�I�K�
�&0����7�#r'i�c��|jj}tt|dd|dd|ddg�\}}}||j|jdzz
z
}||jkr|dz
}tj|||�|jd<y)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.
        r����d�_dateN)r�rw�maprB�
yearThresholdr��dater�)rQr��day�month�years     r(�
_fixDatestampzNMEAAdapter._fixDatestamp�s����#�#�-�-���s�T�!�A�Y��Q�q�	�4��!�9�$E�F���U�D���"�"�d�&8�&8�3�&>�?�?���$�$�$�$��C�K�D�&.�m�m�D�%��&E����7�#r'c�(�|tjurd}nd}t|j|dz�}|j	d�\}}t|dd�t
|dd�d|���}}||dzz}tj||�}	|	|j|<y)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�	longitude�Floatr�Nr6�<)
r
�LATITUDE�getattrr�r;rB�floatr�
Coordinater�)
rQ�coordinateType�coordinateName�nmeaCoordinate�left�right�degrees�minutes�angle�
coordinates
          r(�_fixCoordinateFloatzNMEAAdapter._fixCoordinateFloat�s����V�_�_�,�'�N�(�N� ��!5�!5�~��7O�P��$�*�*�3�/���e��t�C�R�y�>�5�D���I�;�a��w�1G�+H����'�B�,�&���_�_�U�N�;�
�-7����>�*r'Nc�n�|xs|}|j|�}|j|j|�y)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)�_getHemisphereSignr��setSign)rQr��sentenceDataKey�signs    r(�_fixHemisphereSignzNMEAAdapter._fixHemisphereSign�s7��&*�;�^���&�&�~�6�����?�+�3�3�D�9r'c��|tjurd}n8|tjurd}n#|tjurd}nt	d|����t|j|�j�}|dvry|dvryt	d	|����)
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}
        rjrlryzunknown coordinate type �NEr8�SWr:zbad hemisphere/direction: )r
r��	LONGITUDE�	VARIATIONr[r�r��upper)rQr��
hemisphereKey�
hemispheres    r(r�zNMEAAdapter._getHemisphereSigns����V�_�_�,�0�M�
�v�/�/�
/�1�M�
�v�/�/�
/�8�M��7��7G�H�I�I��T�1�1�=�A�G�G�I�
�����
�4�
���9�*��F�G�Gr'c�Z�t|j|�}||�|j|<y)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)r�r�r�)rQre�	converter�currentValues    r(�_convertzNMEAAdapter._converts+���t�3�3�S�9��"+�L�"9����3�r'�heading�_angle�	variationc�\�tjt|�tj�Sr�)r�Angler�r
r�)r�s r(�<lambda>zNMEAAdapter.<lambda>2s��$�*�*�U�5�\�6�3C�3C�D�r'�
positionError�hdop�vdop�pdop)rvrxror�r�c�4�|j|\}}}}||jvr	|j||j|<|t	|j
|��}t
|j|||�y#t$r|�|j|<Y�VwxYw)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_UPDATEr�r�rZr�r��setattr)rQ�sentenceKeyre�factory�attrr��newValues       r(�_statefulUpdatezNMEAAdapter._statefulUpdateHs���&)-�(=�(=�k�(J�%��W�d�I��d�(�(�(�
4�*.�+�+�c�*:��"�"�3�'��W�T�%9�%9�;�G�H����"�"�3�'��x�8��	�
4�*1�)��"�"�3�'�
4�s�A7�7B�B�Mc�`�tjt|�tjz�Sr�)r�Speedr��MPS_PER_KNOT)�inKnotss r(r�zNMEAAdapter.<lambda>hs��T�Z�Z��g���9J�9J�(J�K�r'c�`�tjt|�tjz�Sr�)rrr��MPS_PER_KPH)�inKPHs r(r�zNMEAAdapter.<lambda>is��4�:�:�e�E�l�T�5E�5E�&E�F�r')�N�Kc��|�t|j|�}|�$|�|jd�r|dd}ntd��|�|}||jvr;|j
|}t|j|�}||�|j|<yy)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}
        N�Units���z,valueKey unspecified and couldn't be guessed)r�r��endswithr[�_ACCEPTABLE_UNITS�_UNIT_CONVERTERSr�)rQ�unitKey�valueKey�	sourceKey�unitr�r�s       r(�	_fixUnitszNMEAAdapter._fixUnitsls���4�<��4�/�/��9�D����"�w�'7�'7��'@�"�3�B�<�� �!O�P�P��� �I��t�-�-�-��-�-�d�3�I�"�4�#7�#7��C�L�+4�\�+B�D���x�(�.r'c����tj�}|�jd<d}td�D]S��fd��fd�|D�D�\}}}}|�|��!tj||||�}|j
j
|��Uy)zS
        Parses partial visible satellite information from a GSV sentence.
        �_partialBeaconInformation)r��azimuthr��signalToNoiseRatior�c3�J�K�|]}t�j|����y�wr�)r�r�)�.0r�rQs  �r(�	<genexpr>z&NMEAAdapter._fixGSV.<locals>.<genexpr>�s&�����,����,�,�d�3�,�s� #c3�,�K�|]}d|�fz���
y�w)z%s_%iNr&)rre�indexs  �r(rz&NMEAAdapter._fixGSV.<locals>.<genexpr>�s�����D��W��U�|�3�D�s�N)r�BeaconInformationr��range�	Satellite�seenBeacons�add)	rQ�beaconInformationrc�prnrr��snr�	satelliters	`       @r(�_fixGSVzNMEAAdapter._fixGSV�s����!�2�2�4��:K����6�7�K���1�X�	9�E�,�D�t�D�,�(�C��)�S�
�{�c�k�����s�G�Y��D�I��)�)�-�-�i�8�	9r'c���t�|jd<d�td�D�D]C}t|j|d�}|��|jdjt
|���Ey)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}.
        �	_usedPRNsc3�(K�|]
}d|fz���y�w)zusedSatellitePRN_%dNr&)rrIs  r(rz&NMEAAdapter._fixGSA.<locals>.<genexpr>�s����D�Q�)�Q�D�0�D�s��N)�setr�r!r�r�r$rB)rQrer&s   r(�_fixGSAzNMEAAdapter._fixGSA�sd��+.�%����;�'�D�%��)�D�	>�C��$�.�.��T�:�C����"�"�;�/�3�3�C��H�=�	>r')r�r�c�x�|jj|jj�}|�	||�yy)zA
        Executes a fix for a specific type of sentence.
        N)�_SPECIFIC_SENTENCE_FIXES�getr�rV)rQ�fixers  r(�_sentenceSpecificFixz NMEAAdapter._sentenceSpecificFix�s8���-�-�1�1�$�2F�2F�2K�2K�L�����$�K�r'rVc�"�|j�Sr�)r4r�s r(r�zNMEAAdapter.<lambda>�s��T�6�6�8�r'rhc�"�|j�Sr�)r�r�s r(r�zNMEAAdapter.<lambda>����$�"4�"4�"6�r'rwc�"�|j�Sr�)r�r�s r(r�zNMEAAdapter.<lambda>�r7r'ric�@�|jtj�Sr�)r�r
r�r�s r(r�zNMEAAdapter.<lambda>�s��d�&>�&>�v���&O�r'rjc�B�|jtjd�S)Nr�)r�r
r�r�s r(r�zNMEAAdapter.<lambda>�s��4�+B�+B��O�O�Z�,
�r'rkc�@�|jtj�Sr�)r�r
r�r�s r(r�zNMEAAdapter.<lambda>�s��t�'?�'?��@P�@P�'Q�r'rlc�B�|jtjd�S)Nr�)r�r
r�r�s r(r�zNMEAAdapter.<lambda>�s��D�,C�,C����k�-
�r'rpc�*�|jdd���S)Nrpc�>�tjt|��Sr��r�Altituder���strReprs r(r�z&NMEAAdapter.<lambda>.<locals>.<lambda>�s��$�-�-��g��2O�r'�r��r�r�s r(r�zNMEAAdapter.<lambda>�s������"O�"/�"
�r'rqc�&�|jd��S)Nrq�r�rr�s r(r�zNMEAAdapter.<lambda>�s��d�n�n�_�n�&M�r'rrc�*�|jdd���S)Nrrc�>�tjt|��Sr�r?rAs r(r�z&NMEAAdapter.<lambda>.<locals>.<lambda>�s��d�m�m�E�'�N�&C�r'rCrDr�s r(r�zNMEAAdapter.<lambda>�s���
�
�%�C�1>�1
�r'rsc�&�|jd��S)NrsrFrGr�s r(r�zNMEAAdapter.<lambda>�s��T�^�^�2�6D�6
�r'rvc�$�|jd�S)Nrv�rr�s r(r�zNMEAAdapter.<lambda>�s��D�$8�$8��$G�r'rxc�$�|jd�S)NrxrLr�s r(r�zNMEAAdapter.<lambda>�s��$�*>�*>�?R�*S�r'ryc�B�|jtjd�S)Nr�)r�r
r�r�s r(r�zNMEAAdapter.<lambda>�s��4�3J�3J����i�4
�r'ruc�*�|jddd��S)N�speedrur
)rrrrGr�s r(r�zNMEAAdapter.<lambda>�s��T�^�^���S�&4�&
�r'r�c�$�|jd�S)Nr�rLr�s r(r�zNMEAAdapter.<lambda>����D�4H�4H�)�5
�r'roc�$�|jd�S)NrorLr�s r(r�zNMEAAdapter.<lambda>�s��d�6J�6J�+�7
�r'r�c�$�|jd�S)Nr�rLr�s r(r�zNMEAAdapter.<lambda>�rRr'c� �i|_i|_y)zp
        Resets this adapter.

        This will empty the adapter state and the current sentence data.
        N)r�r�r�s r(�clearzNMEAAdapter.clear�s�������r'c���||_i|_	|j�|j�|j�|j�y#tj
$r|j
�Y�FwxYw)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)	r�r��_validateCurrentSentence�_cleanCurrentSentencerr<rV�_updateState�_fireSentenceCallbacks)rQr=s  r(r^zNMEAAdapter.sentenceReceived�sk�� (������	��)�)�+��&�&�(�	
�����#�#�%��	�#�#�	��J�J�L�	�s� A�#A7�6A7c��|jjtjusL|jjt
jus&|jjtjurtjd��y)z;
        Tests if a sentence contains a valid fix.
        zbad sentenceN)r�rmrrrtr*r.r�r0r1rr<r�s r(rXz$NMEAAdapter._validateCurrentSentencesk��

� � �+�+�/@�/L�/L�L��#�#�,�,�0F�0K�0K�K��#�#�+�+�}�/G�/G�G��&�&�~�6�6�Hr'c��t|jj�D])}|jj	|d�}|��"||��+y)z.
        Cleans the current sentence.
        N)�sortedr��presentAttributes�_FIXERSr2)rQrer3s   r(rYz!NMEAAdapter._cleanCurrentSentence"sG���$�.�.�@�@�A�	�C��L�L�$�$�S�$�/�E�� ��d��		r'c��|j�|j�|jj|j�y)zW
        Updates the current state with the new information from the sentence.
        N)�_updateBeaconInformation�_combineDateAndTimer��updater�r�s r(rZzNMEAAdapter._updateState,s4��	
�%�%�'�� � �"������4�-�-�.r'c�\�|jjd�}|�y|j|�|j|�|jj�rR|jj
�s
|jd=|jjd�}||jd<yy)zJ
        Updates existing beacon information state with new data.
        rNr%)	r�r2�_updateUsedBeacons�_mergeBeaconInformationr�r�r�r��pop)rQ�new�bis   r(rbz$NMEAAdapter._updateBeaconInformation4s���� � �$�$�%@�A���;������$��$�$�S�)����2�2�4��'�'�;�;�=��K�K� ;�<��#�#�'�'�(C�D�B�68�D���2�3�5r'c���|j|jfD]}|jd�}|��ny|jD],}|j|vs�|j
j
|��.y)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}
        r+N)r�r�r2r#�
identifier�usedBeaconsr$)rQr%rH�usedPRNs�beacons     r(rfzNMEAAdapter._updateUsedBeaconsFsu���{�{�D�$6�$6�7�	�F��z�z�+�.�H��#��	�

�'�3�3�	:�F�� � �H�,�!�-�-�1�1�&�9�	:r'c��|jjd�}|�ydD]'}t||�jt||���)y)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 newBeaconInformation: The beacon information object that beacon
            information will be merged into (if necessary).
        @type newBeaconInformation: L{twisted.positioning.base.BeaconInformation}
        rN)r#rm)r�r2r�rd)rQ�newBeaconInformation�oldr�s    r(rgz#NMEAAdapter._mergeBeaconInformation]sM���k�k�o�o�9�:���;��2�	K�D��(�$�/�6�6�w�s�D�7I�J�	Kr'c���t�fd�dD��sy�fd�dD�\}}|�|�ytjj||�}|�jd<y)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}.
        c3�:�K�|]}|�jv���y�wr�)r�)r�krQs  �r(rz2NMEAAdapter._combineDateAndTime.<locals>.<genexpr>ws�����G�q�1��*�*�*�G�s�)r�r�Nc3��K�|]<}�jj|�xs�jj|����>y�wr�)r�r2r�)rrerQs  �r(rz2NMEAAdapter._combineDateAndTime.<locals>.<genexpr>|s?�����
��
���"�"�3�'�?�4�;�;�?�?�3�+?�?�
�s�AAr�)�anyr��combiner�)rQr�r��dts`   r(rczNMEAAdapter._combineDateAndTimepsb����G�4F�G�G�
�
�)�
�
��d�
�<�4�<��
�
�
�
&�
&�t�T�
2��%'����6�"r'c�&�tj}|j�D]_\}}t|j|�}i}d}	|j
D]$}||jvrd}|j|||<�&	|s�X|di|���ay#t$rY�nwxYw)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}.
        FTNr&)	r	�IPositioningReceiver�namesAndDescriptionsr�rO�
positionalr�r�rZ)rQ�iface�name�method�callback�kwargs�atLeastOnePresentInSentence�fields        r(r[z"NMEAAdapter._fireSentenceCallbacks�s����1�1��!�6�6�8�	#�L�D�&��t�~�~�t�4�H��F�*/�'�
�#�.�.�7�E��� 2� 2�2�6:�3�$(�K�K��$6�F�5�M�7�+��"�6�"�	#���
��
�s�3B�	B�Br�)NNNN)%rrrrrTr�r�r�r�r�r�r�r�Headingr��
PositionErrorr�r�	frozensetrrrr)r/r1r4r`rVr^rXrYrZrbrfrgrcr[r&r'r(r�r��s/��#�J	"�1��M�F� 8�(:�.H�8:�"�4�<�<��5�A���L�L��D�	
�
������	*
�
������	(
�
������	(
�+��:9�<"�3�%�(��
K�
F���
'C�R9�6
>� �� ��
�(��8�(��6�(�	�6�(�	�O�	(�
	�
�(�	�Q�(�	� 
�(�	�
�(�	�M�(� 	"�$
�!(�(	'�)
�)(�.	�G�/(�0	�S�1(�2	%�'
�3(�8	�
�9(�>	&�(
�?(�D	(�*
�E(�J	&�(
�K(�G�T �&�0	7��/�9�$:�.K�&(�.#r'r�)rMr]r�)!rr�rC�	functoolsr�zope.interfacer�
constantlyrr�twisted.positioningrrr	�twisted.positioning.baser
�twisted.protocols.basicr�twisted.python.compatrr
rr*r0r>rK�!_PositioningSentenceProducerMixinrM�
_BaseSentencer]�
INMEAReceiverr��__all__r&r'r(�<module>r�s����&���&�,�=�=�+�0�9�&��&�R
�V�
� $�F�$�E�&M�&b�<��!L�!L�b�JPB�9�*�*�PB�f
�\�
'�
'�(�V#�V#�)�V#�r:�r'

Zerion Mini Shell 1.0