Ϫfo&dZddlmZddlmZddlmZmZddlm Z ddl m Z m Z ddl mZddlmZd Zd Zd ZGd d e ZGdde Ze ej,GddZGddeZGddeZGddeZGddeZGddeZGddeZGddeZGd d!eZ Gd"d#eZ!Gd$d%eZ"Gd&d'Z#e ejHGd(d)Z%Gd*d+e%Z&gd,Z'y-).z1 Generic positioning base classes. @since: 14.0 )partial) attrgetter)ClassVarSequence) implementer) NamedConstantNames) ipositioning) FancyEqMixing2Tv?grq?gׁ?cHeZdZdZeZeZeZeZy)Anglesa The types of angles. @cvar LATITUDE: Angle representing a latitude of an object. @type LATITUDE: L{NamedConstant} @cvar LONGITUDE: Angle representing the longitude of an object. @type LONGITUDE: L{NamedConstant} @cvar HEADING: Angle representing the heading of an object. @type HEADING: L{NamedConstant} @cvar VARIATION: Angle representing a magnetic variation. @type VARIATION: L{NamedConstant} N) __name__ __module__ __qualname____doc__rLATITUDE LONGITUDEHEADING VARIATION:/usr/lib/python3/dist-packages/twisted/positioning/base.pyr r s%"HIoGIrr cHeZdZdZeZeZeZeZy) DirectionszB The four cardinal directions (north, east, south, west). N) rrrrrNORTHEASTSOUTHWESTrrrrr3s% OE ?D OE ?Drrc@eZdZdZdZdZdZdZdZdZ dZ d Z y ) BasePositioningReceiveraS A base positioning receiver. This class would be a good base class for building positioning receivers. It implements the interface (so you don't have to) with stub methods. People who want to implement positioning receivers should subclass this class and override the specific callbacks they want to handle. cy)zG Implements L{IPositioningReceiver.timeReceived} stub. Nr)selftimes r timeReceivedz$BasePositioningReceiver.timeReceivedKrcy)zJ Implements L{IPositioningReceiver.headingReceived} stub. Nr)r"headings rheadingReceivedz'BasePositioningReceiver.headingReceivedPr%rcy)zH Implements L{IPositioningReceiver.speedReceived} stub. Nrr"speeds r speedReceivedz%BasePositioningReceiver.speedReceivedUr%rcy)zH Implements L{IPositioningReceiver.climbReceived} stub. Nrr"climbs r climbReceivedz%BasePositioningReceiver.climbReceivedZr%rcy)zK Implements L{IPositioningReceiver.positionReceived} stub. Nr)r"latitude longitudes rpositionReceivedz(BasePositioningReceiver.positionReceived_r%rcy)zP Implements L{IPositioningReceiver.positionErrorReceived} stub. Nr)r" positionErrors rpositionErrorReceivedz-BasePositioningReceiver.positionErrorReceiveddr%rcy)zK Implements L{IPositioningReceiver.altitudeReceived} stub. Nrr"altitudes raltitudeReceivedz(BasePositioningReceiver.altitudeReceivedir%rcy)zT Implements L{IPositioningReceiver.beaconInformationReceived} stub. Nr)r"beaconInformations rbeaconInformationReceivedz1BasePositioningReceiver.beaconInformationReceivednr%rN) rrrrr$r(r,r0r4r7r;r>rrrr r >s/         rr ceZdZdZy)InvalidSentencez9 An exception raised when a sentence is invalid. Nrrrrrrrr@r@trr@ceZdZdZy)InvalidChecksumzI An exception raised when the checksum of a sentence is invalid. NrArrrrDrDzrBrrDc\eZdZUdZej dej dejdejdiZ ej dej dejdejd iZ d Z e e eed <dd ZedZedZdZdZdefdZedZedZy )Anglea An object representing an angle. @cvar _RANGE_EXPRESSIONS: A collection of expressions for the allowable range for the angular value of a particular coordinate value. @type _RANGE_EXPRESSIONS: C{dict} of L{Angles} constants to callables @cvar _ANGLE_TYPE_NAMES: English names for angle types. @type _ANGLE_TYPE_NAMES: C{dict} of L{Angles} constants to C{str} c"d|cxkxrdkScS)NgVgV@r)r2s rzAngle.s%(*AT*A*Arc"d|cxkxrdkScS)Ngfgf@r)r3s rrHzAngle.sFY,F,F,Frc"d|cxkxrdkScS)Nrhr)r's rrHzAngle.sW(:s(:(:rc"d|cxkxrdkScS)NiLr) variations rrHzAngle.sD9,C,C,CrLatitude Longitude VariationHeading) angleTypeinDecimalDegreescompareAttributesNc|||jvr td|6|4|j|}||sd}t|j||||_||_y)aG Initializes an angle. @param angle: The value of the angle in decimal degrees. (L{None} if unknown). @type angle: C{float} or L{None} @param angleType: A symbolic constant describing the angle type. Should be one of L{Angles} or {None} if unknown. @raises ValueError: If the angle type is not the default argument, but it is an unknown type (not in C{Angle._RANGE_EXPRESSIONS}), or it is a known type but the supplied value was out of the allowable range for said type. NzUnknown angle typez+Angle {0} not in allowed range for type {1})_RANGE_EXPRESSIONS ValueErrorformatrS_angle)r"anglerSrangeExpressiontemplates r__init__zAngle.__init__so  Yd6M6M%M12 2  !6"55i@O"5)H  !BCC" rc|jS)z The value of this angle in decimal degrees. This value is immutable. @return: This angle expressed in decimal degrees, or L{None} if the angle is unknown. @rtype: C{float} (or L{None}) rZr"s rrTzAngle.inDecimalDegrees{{rc|jytt|j}t|jt|jz }d|z}t|}|t|z }d|z}||t|fS)a The value of this angle as a degrees, minutes, seconds tuple. This value is immutable. @return: This angle expressed in degrees, minutes, seconds. L{None} if the angle is unknown. @rtype: 3-C{tuple} of C{int} (or L{None}) N<)rZabsint)r"degreesfractionalDegreesdecimalMinutesminutesfractionalMinutesdecimalSecondss rinDegreesMinutesSecondszAngle.inDegreesMinutesSecondss ;; c$++&' c$++.> >?//n%*S-@@//^!444rcb|dvrtd|z|t|jz|_y)a Sets the sign of this angle. @param sign: The new sign. C{1} for positive and C{-1} for negative signs, respectively. @type sign: C{int} @raise ValueError: If the C{sign} parameter is not C{-1} or C{1}. )z#bad sign (got %s, expected -1 or 1)N)rXrerZr"signs rsetSignz Angle.setSigns2 w BTIJ JS-- rc|jS)z Returns this angle as a float. @return: The float value of this angle, expressed in degrees. @rtype: C{float} r`ras r __float__zAngle.__float__s{{rreturnc&dj|S) Returns a string representation of this angle. @return: The string representation. @rtype: C{str} z.<{s._angleTypeNameRepr} ({s._angleValueRepr})>srYras r__repr__zAngle.__repr__s@FFFNNrcN|jdt|jdzSy)z Returns a string representation of the angular value of this angle. This is a helper function for the actual C{__repr__}. @return: The string representation. @rtype: C{str} z %s degreesz unknown value)rTroundras r_angleValueReprzAngle._angleValueReprs+  ,%(=(=q"AA A"rcT |j|jS#t$rYywxYw)z Returns a string representation of the type of this angle. This is a helper function for the actual C{__repr__}. @return: The string representation. @rtype: C{str} zAngle of unknown type)_ANGLE_TYPE_NAMESrSKeyErrorras r_angleTypeNameReprzAngle._angleTypeNameRepr s. +))$..9 9 +* +s  ''NN)rrrrr rrrrrWrrUrrstr__annotations__r^propertyrTrmrsrur|rrrrrrFrFs AF:C  ++ 2x . 855, .O#O # # + +rrFcxeZdZdZd dZed dZedZdZ e e jdgzZ de fd Zy) rRa The heading of a mobile object. @ivar variation: The (optional) magnetic variation. The sign of the variation is positive for variations towards the east (clockwise from north), and negative for variations towards the west (counterclockwise from north). If the variation is unknown or not applicable, this is L{None}. @type variation: C{Angle} or L{None}. @ivar correctedHeading: The heading, corrected for variation. If the variation is unknown (L{None}), is None. This attribute is read-only (its value is determined by the angle and variation attributes). The value is coerced to being between 0 (inclusive) and 360 (exclusive). Nc\tj||tj||_y)zB Initializes an angle with an optional variation. N)rFr^r rrN)r"r[rNs rr^zHeading.__init__,s tUFNN3"rcHt|tj}|||S)a_ Constructs a Heading from the float values of the angle and variation. @param angleValue: The angle value of this heading. @type angleValue: C{float} @param variationValue: The value of the variation of this heading. @type variationValue: C{float} @return: A L{Heading} with the given values. )rFr r)cls angleValuevariationValuerNs r fromFloatszHeading.fromFloats3s#.&*:*:; :y))rc|j |jy|j|jjz dz}t|tj S)a Corrects the heading by the given variation. This is sometimes known as the true heading. @return: The heading, corrected by the variation. If the variation or the angle are unknown, returns L{None}. @rtype: C{float} or L{None} NrK)rZrNrTrFr r)r"r[s rcorrectedHeadingzHeading.correctedHeadingAsJ ;; $.."8&&)H)HHCOUFNN++rc||jj td|jj|y)a Sets the sign of the variation of this heading. @param sign: The new sign. C{1} for positive and C{-1} for negative signs, respectively. @type sign: C{int} @raise ValueError: If the C{sign} parameter is not C{-1} or C{1}. Nz*can't set the sign of an unknown variation)rNrTrXrsrqs rrszHeading.setSignQs2 >> * * 2IJ J t$rrNrvc|jd}nt|j}dj|j|j|S)rxzunknown variationz <{} ({}, {})>)rNreprrYrr)r" variationReprs rr|zHeading.__repr__bsI >> !/M 0M%%  # #    rr)rrrrr^ classmethodrrrrslistrFrUrr|rrrrRrRs_ # * * , , %U445 E # rrRc(eZdZdZddZedZy) Coordinatea A coordinate. @ivar angle: The value of the coordinate in decimal degrees, with the usual rules for sign (northern and eastern hemispheres are positive, southern and western hemispheres are negative). @type angle: C{float} Nc|tjtjdfvrtdj |t j |||y)aM Initializes a coordinate. @param angle: The angle of this coordinate in decimal degrees. The hemisphere is determined by the sign (north and east are positive). If this coordinate describes a latitude, this value must be within -90.0 and +90.0 (exclusive). If this value describes a longitude, this value must be within -180.0 and +180.0 (exclusive). @type angle: C{float} @param coordinateType: The coordinate type. One of L{Angles.LATITUDE}, L{Angles.LONGITUDE} or L{None} if unknown. NzQcoordinateType must be one of Angles.LATITUDE, Angles.LONGITUDE or None, was {!r})r rrrXrYrFr^)r"r[coordinateTypes rr^zCoordinate.__init__sK &//63C3CT!J J55;VN5K  tUN3rcD|jtjur/|jdkrtj Stj S|jtjur/|jdkrtjStjStd)z Gets the hemisphere of this coordinate. @return: A symbolic constant representing a hemisphere (one of L{Angles}) rz.unknown coordinate type (cant find hemisphere)) rSr rrTrrrrrrrXras r hemispherezCoordinate.hemispheresz >>V__ ,$$q(!'''!''' ^^v// /$$q(!&!&MN NrN)rrrrr^rrrrrrrus"4*OOrrcLeZdZdZdZdZedZedZdZ de fdZ y ) Altitudez An altitude. @ivar inMeters: The altitude represented by this object, in meters. This attribute is read-only. @type inMeters: C{float} @ivar inFeet: As above, but expressed in feet. @type inFeet: C{float} )inMetersc||_y)z} Initializes an altitude. @param altitude: The altitude in meters. @type altitude: C{float} N _altituder9s rr^zAltitude.__init__s "rc(|jtz S)z Gets the altitude this object represents, in feet. @return: The altitude, expressed in feet. @rtype: C{float} )rMETERS_PER_FOOTras rinFeetzAltitude.inFeets~~//rc|jS)z Returns the altitude this object represents, in meters. @return: The altitude, expressed in feet. @rtype: C{float} rras rrzAltitude.inMeterss~~rc|jS)z Returns the altitude represented by this object expressed in meters. @return: The altitude represented by this object, expressed in meters. @rtype: C{float} rras rruzAltitude.__float__s~~rrvc"d|jdS)z Returns a string representation of this altitude. @return: The string representation. @rtype: C{str} z rras rr|zAltitude.__repr__sT^^,D11rN) rrrrrUr^rrrrurr|rrrrrsM &"002#2rrcLeZdZdZdZdZedZedZdZ de fdZ y ) _BaseSpeedz An object representing the abstract concept of the speed (rate of movement) of a mobile object. This primarily has behavior for converting between units and comparison. )inMetersPerSecondc||_y)a2 Initializes a speed. @param speed: The speed that this object represents, expressed in meters per second. @type speed: C{float} @raises ValueError: Raised if value was invalid for this particular kind of speed. Only happens in subclasses. N_speedr*s rr^z_BaseSpeed.__init__s  rc|jS)z The speed that this object represents, expressed in meters per second. This attribute is immutable. @return: The speed this object represents, in meters per second. @rtype: C{float} rras rrz_BaseSpeed.inMetersPerSecondrbrc(|jtz S)z Returns the speed represented by this object, expressed in knots. This attribute is immutable. @return: The speed this object represents, in knots. @rtype: C{float} )r MPS_PER_KNOTras rinKnotsz_BaseSpeed.inKnots s{{\))rc|jS)z Returns the speed represented by this object expressed in meters per second. @return: The speed represented by this object, expressed in meters per second. @rtype: C{float} rras rruz_BaseSpeed.__float__rbrrvcht|jd}d|jjd|dS)z Returns a string representation of this speed object. @return: The string representation. @rtype: C{str} r~)rr __class__r)r" speedValues rr|z_BaseSpeed.__repr__!s641115 4>>**+2j\@@rN) rrrrrUr^rrrrurr|rrrrrsO/ ** A#ArrceZdZdZdZy)Speedz: The speed (rate of movement) of a mobile object. cV|dkrtd|tj||y)z Initializes a L{Speed} object. @param speed: The speed that this object represents, expressed in meters per second. @type speed: C{float} @raises ValueError: Raised if C{speed} is negative. rznegative speed: N)rXrr^r*s rr^zSpeed.__init__1s. 19/y9: :D%(rNrrrrr^rrrrr,s  )rrceZdZdZdZy)Climbz4 The climb ("vertical speed") of an object. c0tj||y)z Initializes a L{Climb} object. @param climb: The climb that this object represents, expressed in meters per second. @type climb: C{float} N)rr^r.s rr^zClimb.__init__Fs D%(rNrrrrrrAs )rrceZdZdZdZddZdZdZddgd d gd d gdZd Z dZ e dZ e jdZ e dZejdZe dZejdZdZdefdZy) PositionErrora# Position error information. @cvar _ALLOWABLE_THRESHOLD: The maximum allowable difference between PDOP and the geometric mean of VDOP and HDOP. That difference is supposed to be zero, but can be non-zero because of rounding error and limited reporting precision. You should never have to change this value. @type _ALLOWABLE_THRESHOLD: C{float} @cvar _DOP_EXPRESSIONS: A mapping of DOP types (C[hvp]dop) to a list of callables that take self and return that DOP type, or raise C{TypeError}. This allows a DOP value to either be returned directly if it's know, or computed from other DOP types if it isn't. @type _DOP_EXPRESSIONS: C{dict} of C{str} to callables @ivar pdop: The position dilution of precision. L{None} if unknown. @type pdop: C{float} or L{None} @ivar hdop: The horizontal dilution of precision. L{None} if unknown. @type hdop: C{float} or L{None} @ivar vdop: The vertical dilution of precision. L{None} if unknown. @type vdop: C{float} or L{None} )pdophdopvdopNc\||_||_||_||_|j y)a Initializes a positioning error object. @param pdop: The position dilution of precision. L{None} if unknown. @type pdop: C{float} or L{None} @param hdop: The horizontal dilution of precision. L{None} if unknown. @type hdop: C{float} or L{None} @param vdop: The vertical dilution of precision. L{None} if unknown. @type vdop: C{float} or L{None} @param testInvariant: Flag to test if the DOP invariant is valid or not. If C{True}, the invariant (PDOP = (HDOP**2 + VDOP**2)*.5) is checked at every mutation. By default, this is false, because the vast majority of DOP-providing devices ignore this invariant. @type testInvariant: c{bool} N)_pdop_hdop_vdop_testInvariant _testDilutionOfPositionInvariant)r"rrr testInvariants rr^zPositionError.__init__is-    + --/rg{Gz?ch|jsy|j|j|jfD]}|yt |j|jdz|jdzzdzz }||j kDr2t d|jd|jd|jy)a Tests if this positioning error object satisfies the dilution of position invariant (PDOP = (HDOP**2 + VDOP**2)*.5), unless the C{self._testInvariant} instance variable is C{False}. @return: L{None} if the invariant was not satisfied or not tested. @raises ValueError: Raised if the invariant was tested but not satisfied. Nr~?z9invalid combination of dilutions of precision: position: z, horizontal: z , vertical: )rrrrre_ALLOWABLE_TRESHOLDrX)r"xdeltas rrz.PositionError._testDilutionOfPositionInvariants"" ))TYY 2 Ay DIIA 1 !< DDE 4++ +99dii4  ,rc,t|jSr)floatrras rrHzPositionError.tzz*rcF|jdz|jdzzdzSNr~r)rrras rrHzPositionError. $**a-$**a-7C?rc,t|jSr)rrras rrHzPositionError.rrcF|jdz|jdzz dzSr)rrras rrHzPositionError.rrc,t|jSr)rrras rrHzPositionError.rrcF|jdz|jdzz dzSr)rrras rrHzPositionError.rrc^|j|D] } ||cSy#t$rYwxYw)a, Gets a particular dilution of position value. @param dopType: The type of dilution of position to get. One of ('pdop', 'hdop', 'vdop'). @type dopType: C{str} @return: The DOP if it is known, L{None} otherwise. @rtype: C{float} or L{None} N)_DOP_EXPRESSIONS TypeError)r"dopType dopExpressions r_getDOPzPositionError._getDOPsB"227; M $T**   s   ,,cd|z}t||}t||t| |jy#t$rt|||wxYw)a Sets a particular dilution of position value. @param dopType: The type of dilution of position to set. One of ('pdop', 'hdop', 'vdop'). @type dopType: C{str} @param value: The value to set the dilution of position type to. @type value: C{float} If this position error tests dilution of precision invariants, it will be checked. If the invariant is not satisfied, the assignment will be undone and C{ValueError} is raised. _N)getattrsetattrrrrX)r"rvalue attributeNameoldValues r_setDOPzPositionError._setDOPsXg 4/mU5\2   1 1 3  D- 2  s :Ac$|jdSNrrras rrzPositionError.pdop||F##rc&|jd|Srrr"rs rrzPositionError.pdop||FE**rc$|jdSNrrras rrzPositionError.hdoprrc&|jd|Srrrs rrzPositionError.hdoprrc$|jdSNrrras rrzPositionError.vdoprrc&|jd|Srrrs rrzPositionError.vdoprrz.rvcb|j|j|j|jfzS)z Returns a string representation of positioning information object. @return: The string representation. @rtype: C{str} )_REPR_TEMPLATErrrras rr|zPositionError.__repr__s(""diiDII%FFFr)NNNF)rrrrrUr^rrrrrrrsetterrrrrr|rrrrrQs*/0.6 + ? + ? + ?   4$$ [[++$$ [[++$$ [[++FNG#Grrc$eZdZdZddZdefdZy)BeaconInformationa Information about positioning beacons (a generalized term for the reference objects that help you determine your position, such as satellites or cell towers). @ivar seenBeacons: A set of visible beacons. Note that visible beacons are not necessarily used in acquiring a positioning fix. @type seenBeacons: C{set} of L{IPositioningBeacon} @ivar usedBeacons: A set of the beacons that were used in obtaining a positioning fix. This only contains beacons that are actually used, not beacons for which it is unknown if they are used or not. @type usedBeacons: C{set} of L{IPositioningBeacon} cBt||_t|_y)z Initializes a beacon information object. @param seenBeacons: A collection of beacons that are currently seen. @type seenBeacons: iterable of L{IPositioningBeacon}s N)set seenBeacons usedBeacons)r"rs rr^zBeaconInformation.__init__s{+5rrvctttd}||j}||j|jz }d}|j t |j||}|S)z Returns a string representation of this beacon information object. The beacons are sorted by their identifier. @return: The string representation. @rtype: C{str} identifier)keyz^)numUsedr unusedBeacons)rsortedrrrrYlen)r" sortedBeaconsrrr] formatteds rr|zBeaconInformation.__repr__s{ J|,DE #D$4$45 %d&6&69I9I&IJ  0  OO(()#'$ rN)rrrrrr^rr|rrrrrs !#rrc(eZdZdZdZdZdefdZy)PositioningBeacona$ A positioning beacon. @ivar identifier: The unique identifier for this beacon. This is usually an integer. For GPS, this is also known as the PRN. @type identifier: Pretty much anything that can be used as a unique identifier. Depends on the implementation. c||_y)z Initializes a positioning beacon. @param identifier: The identifier for this beacon. @type identifier: Can be pretty much anything (see ivar documentation). Nr)r"rs rr^zPositioningBeacon.__init__9s %rc,t|jS)z Returns the hash of the identifier for this beacon. @return: The hash of the identifier. (C{hash(self.identifier)}) @rtype: C{int} )hashrras r__hash__zPositioningBeacon.__hash__BsDOO$$rrvc"d|jdS)z Returns a string representation of this beacon. @return: The string representation. @rtype: C{str} z rras rr|zPositioningBeacon.__repr__Ks4??+2..rN)rrrrr^rrr|rrrr r .s%%/#/rr c&eZdZdZ ddZdefdZy) Satellitea A satellite. @ivar azimuth: The azimuth of the satellite. This is the heading (positive angle relative to true north) where the satellite appears to be to the device. @ivar elevation: The (positive) angle above the horizon where this satellite appears to be to the device. @ivar signalToNoiseRatio: The signal to noise ratio of the signal coming from this satellite. Ncltj|t|||_||_||_y)ar Initializes a satellite object. @param identifier: The PRN (unique identifier) of this satellite. @type identifier: C{int} @param azimuth: The azimuth of the satellite (see instance variable documentation). @type azimuth: C{float} @param elevation: The elevation of the satellite (see instance variable documentation). @type elevation: C{float} @param signalToNoiseRatio: The signal to noise ratio of the connection to this satellite (see instance variable documentation). @type signalToNoiseRatio: C{float} N)r r^rfazimuth elevationsignalToNoiseRatio)r"rrrrs rr^zSatellite.__init__bs.$ ""4Z9 ""4rrvc*d}|j|S)z Returns a string representation of this Satellite. @return: The string representation. @rtype: C{str} ziryr{)r"r]s rr|zSatellite.__repr__zs + &&r)NNNr rrrrrUs LP50'#'rr)rrFr r rrrrrRrDr@rr MPS_PER_KPHrr rrN)(r functoolsroperatorrtypingrrzope.interfacer constantlyrr twisted.positioningr twisted.python.utilr rrrr rIPositioningReceiverr Exceptionr@rDrFrRrrrrrrrIPositioningBeaconr r__all__rrrr&s>%&+,,! !  U 0 \ . ./2 2 02 ji i Y+LY+xV eV r3O3Ol;2|;2|@A@AF)J)* )J ) dGLdGN33l \ , ,-#/#/.#/L3'!3'l r