ó
[³XMc           @   s¨   d  Z  d d l Z d d l m Z d d l m Z d \ Z Z Z Z	 d \ Z
 Z d \ Z Z Z d e f d „  ƒ  YZ d e f d „  ƒ  YZ d e j f d „  ƒ  YZ d S(   s¹  NMEA 0183 implementation

Maintainer: Bob Ippolito

The following NMEA 0183 sentences are currently understood::
    GPGGA (fix)
    GPGLL (position)
    GPRMC (position and time)
    GPGSA (active satellites)
 
The following NMEA 0183 sentences require implementation::
    None really, the others aren't generally useful or implemented in most devices anyhow

Other desired features::
    - A NMEA 0183 producer to emulate GPS devices (?)
iÿÿÿÿN(   t   basic(   t   reducei    i   i   i   t   At   Mt   InvalidSentencec           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyR      s   t   InvalidChecksumc           B   s   e  Z RS(    (   R   R   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyR   !   s   t   NMEAReceiverc           B   s¾   e  Z d  Z d Z i d d 6d d 6d d 6d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6Z d Z d Z d Z d Z d „  Z	 d „  Z
 d „  Z d „  Z d „  Z d „  Z d  „  Z RS(!   s`   This parses most common NMEA-0183 messages, presumably from a serial GPS device at 4800 bps
    s   
t   fixt   GPGGAt   positiont   GPGLLt   activesatellitest   GPGSAt   positiontimet   GPRMCt   viewsatellitest   GPGSVt   courset   GPVTGt   almanact   GPALMt   ranget   GPGRSt   noiset   GPGSTt   beacont   GPMSSt   timet   GPZDAi   i    c         C   s˜  | j  d ƒ s2 |  j r d  St d | f ƒ ‚ n  | d j ƒ  j d ƒ \ } } | j d ƒ } | d | d } } |  j j | d  ƒ } | r± |  j r± t d | f ƒ ‚ n  |  j	 st
 | d ƒ t t j t t | ƒ ƒ } } | | k rt d	 | | f ƒ ‚ qn  t |  d
 | d  ƒ } t |  d | d  ƒ }	 | oH| oH|	 sOd  Sy |	 | Œ  }
 Wn, t k
 r} t d | | | f ƒ ‚ n X| |
 Œ  S(   Nt   $s   %r does not begin with $i   t   *t   ,i    s   sentencetype %ri   s   Given 0x%02X != 0x%02Xs	   handle_%ss	   decode_%ss"   %r is not a valid %s (%s) sentence(   t
   startswitht   ignore_invalid_sentenceR   t   stript   splitt   dispatcht   gett   Nonet   ignore_unknown_sentencetypest   ignore_checksum_mismatcht   intR   t   operatort   xort   mapt   ordR   t   getattrt	   Exception(   t   selft   linet
   strmessaget   checksumt   messaget   sentencetypeR&   t   calculated_checksumt   handlert   decodert   decodedt   e(    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyt   lineReceived>   s.    		+c         C   sX   |  j  | | | | ƒ \ } } |  j | ƒ } | d k rB d } n d } | | | | f S(   NR   i   i    (   t   _decode_latlont   _decode_utc(   R2   t   latitudet   nst	   longitudet   ewt   utct   status(    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyt   decode_positionZ   s    	c         C   s4  |  j  | ƒ } |  j | | | | ƒ \ } } | d k rH t | ƒ } n d  } | d k ri t | ƒ } n d  } d t |	 d d !ƒ t |	 d d !ƒ t |	 d d !ƒ f }	 |  j rä |	 d d k rä |	 d d |	 d	 |	 d f }	 n  |
 d k rÿ t |
 ƒ }
 n  | d
 k r|
 }
 n d  }
 | | | | | |	 |
 f S(   Nt    iÐ  i   i   i   i    i  id   i   t   W(   R?   R>   t   floatR(   R+   t   convert_dates_before_y2k(   R2   RD   RE   R@   RA   RB   RC   t   speedR   t   utcdatet   magvart   magdir(    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyt   decode_positiontimeh   s.    :"
c         C   sD   t  t | d  | d d !| d f ƒ \ } } } | d | d | S(   Ni   i   g      ¬@g      N@(   R.   RI   (   R2   RD   t   utc_hht   utc_mmt   utc_ss(    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyR?   Œ   s    0c         C   sz   t  | d  ƒ t  | d ƒ d } | d k r8 | } n  t  | d  ƒ t  | d ƒ d } | d k rp | } n  | | f S(   Ni   g      N@t   Si   RH   (   RI   (   R2   R@   RA   RB   RC   (    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyR>      s    "
"
c         G   s’   | d  t  t | d ƒ } \ } } } g  } x7 | D]/ }	 |	 rV | j t |	 ƒ ƒ q4 | j d  ƒ q4 W| t | ƒ f }
 t | ƒ |
 | | | f S(   Ni   (   R.   RI   t   appendR+   R(   t   tuple(   R2   t   mode1t   mode2t   argst
   satellitest   pdopt   hdopt   vdopt   satlistt   nt   mode(    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyt   decode_activesatellites™   s    '	c      	   C   sÐ   |  j  | | | | ƒ \ } } |  j | ƒ } t | ƒ } t | ƒ } t | ƒ } t |	 ƒ |
 f }	 | d k r„ t | ƒ | f } n d  } | d k r« t | ƒ | f } n d  } | | | | | | |	 | | f	 S(   NRG   (   R>   R?   R+   RI   R(   (   R2   RD   R@   RA   RB   RC   t   posfixRY   R[   t   altitudet   altitude_unitst   geoid_separationt   geoid_separation_unitst   dgps_aget   dgps_station_idt   geoidt   dgps(    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyt
   decode_fix¯   s*    (   R   R   t   __doc__t	   delimiterR&   R#   R*   R)   RJ   R=   RF   RO   R?   R>   R`   Rj   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyR   $   s2   
			$				(   i    i   i   i   (   R   R   (   i   i   i   (   Rk   R,   t   twisted.protocolsR    t   twisted.python.compatR   t   POSFIX_INVALIDt
   POSFIX_SPSt   POSFIX_DGPSt
   POSFIX_PPSt	   MODE_AUTOt   MODE_FORCEDt
   MODE_NOFIXt   MODE_2Dt   MODE_3DR1   R   R   t   LineReceiverR   (    (    (    s>   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/nmea.pyt   <module>   s   