
[XMc           @   s   d  Z  d d l Z d d l Z d d l Z d d l m Z d d l m Z d Z d e	 f d     YZ
 d e j f d	     YZ d S(
   s  Rockwell Semiconductor Zodiac Serial Protocol
Coded from official protocol specs (Order No. GPS-25, 09/24/1996, Revision 11)

Maintainer: Bob Ippolito

The following Rockwell Zodiac messages are currently understood::
    EARTHA\r\n (a hack to "turn on" a DeLorme Earthmate)
    1000 (Geodesic Position Status Output)
    1002 (Channel Summary)
    1003 (Visible Satellites)
    1011 (Receiver ID)

The following Rockwell Zodiac messages require implementation::
    None really, the others aren't quite so useful and require bidirectional communication w/ the device

Other desired features::
    - Compatability with the DeLorme Tripmate and other devices with this chipset (?)
iN(   t   protocol(   t   logi   t   ZodiacParseErrorc           B   s   e  Z RS(    (   t   __name__t
   __module__(    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyR      s   t   Zodiacc           B   s  e  Z i d  d 6d d 6d d 6d d 6d d	 6d
 d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6d d 6Z i d d  6d d 6d d  6d! d" 6d# d$ 6d% d& 6d' d( 6d) d* 6d+ d, 6d- d. 6d/ d0 6d1 d2 6d3 d4 6d5 d6 6d7 d 6d8 d9 6d: d; 6Z d< Z d= Z d> Z d?   Z d@   Z dA   Z	 dB   Z
 dC   Z dD   Z dE   Z dF   Z dG   Z dH   Z dI   Z dJ   Z dK   Z dL   Z dM   Z dN   Z RS(O   t   fixi  t   ecefi  t   channelsi  t
   satellitesi  t   dgpsi  t   channelmeasi  t   idi  t   usersettingsi  t   testresultsiL  t   meastimemarkiN  t   utctimemarkiT  t   serialij  t   eepromupdateio  t   eepromstatusip  i  i  t   udatumi  t   mdatumi  t   smaski  t   sselecti  t   dgpsci  t   startci  t   svalidi  t   antennai  t   altinputi  t   appctli  t   navcfgi  t   testi  t   restarti2  i3  t   msgctliG  t   dgpsdi(  i   t    c   
      C   s  |  j  | |  _  xt |  j   d k r|  j  d  d k rv |  j r` d |  _ |  j j d  n  |  j  d |  _  q n  |  j  d d !d k r t r t d |  j    q t  n  t j d |  j  d   \ } } } } } t	 t
 j | | | | f  d	 @} t j d
 t j d
 |   \ } | | k r[t rRt d | | |  j  d  f   q[t  n  | d } d } | r| | d 7} n  t |  j   | k  rPn  | |  j k rt d   n  d }	 | r|  j  d d | !t j d
 |  j  d | | ! d }	 } d t	 t
 j t j d | d |	   d	 @} t j d
 t j d
 |   \ } | | k rt rt j d | | f d t t d | | |	 f   qt  qn  |  j  | |  _  |  j | |	 |  q Wd  S(   Ni
   i   s   EARTHA
i    i   s   s   Invalid Sync %rs   <HHHHhi  s   <hs#   Invalid Header Checksum %r != %r %rs   Invalid Header??R#   i   s   <%dHs   msg_id = %r length = %rt   debugs!   Invalid Data Checksum %r != %r %r(   t   recvdt   lent   allow_earthmate_hackt	   transportt   writet   DEBUGR   t   structt   unpackt   reducet   operatort   addt   packt
   MAX_LENGTHR   t   dmsgt   Truet   receivedMessage(
   t   selft   recdt   synct   msg_idt   lengtht   acknakt   checksumt   cksumt   neededBytest   message(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   dataReceivedL   sN    			(#!#	
9.!c         C   s   |  j  j | d   } | s. t d |   n  t |  d | d   } t |  d | d   } | oc | sj d  S| |  } | |   S(   Ns   Unknown msg_id = %rs	   handle_%ss	   decode_%s(   t   dispatcht   gett   NoneR   t   getattr(   R5   R8   R>   R:   R@   t   handlert   decodert   decoded(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyR4      s    c   +   "   C   s  t  |  d k s t d  t j d |  \" } } } } } } } }	 }
 } } } } } } } } } } } } } } } } } } } } } }  }! }" }# | d | d | t |  d }$ t j d t | | | | f  d t t |  d	 t	 j
 } t |  d	 t	 j
 } | d
 @}% | }& t |  d }' t |  d d f }( t |  d d f }) d  }* |$ | | |% |& |' |( |) |* f	 S(   Nib   sJ   Geodesic Position Status Output should be 55 words total (98 byte message)s#   <LhhHHHHHLLHHHHHHLlllhLHhhHLLLHllllg      @g      N@g&.>s   utchr, utcmn, utcsc, utcns = R$   g1E2>i   g{Gz?t   M(   R&   t   AssertionErrorR+   R,   t   floatR   t   msgt   reprR3   t   matht   piRB   (+   R5   R>   t   tickst   msgseqt   satseqt	   navstatust   navtypet   nmeasuret   polart   gpswkt   gpsest   gpsnst   utcdyt   utcmot   utcyrt   utchrt   utcmnt   utcsct   utcnst   latitudet	   longitudet   heightt
   geoidalsept   speedt   courset   magvart   climbt   mapdatumt	   exhposerrt	   exvposerrt	   extimeerrt
   exphvelerrt   clkbiast
   clkbiasdevt   clkdriftt   clkdriftdevt   utct   posfixR	   t   hdopt   altitudet   geoidR
   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt
   decode_fix   s*    x$)c         C   s   t  |  d k s t d  t j d |  \ } } } } } } } t d   | | | | f  \ } } } } t |  } t |  } t | d  d  } | d @d k }	 | d	 @d k }
 | | f |	 |
 f f S(
   Nij   s?   Receiver ID Message should be 59 words total (106 byte message)s   <Lh20s20s20s20s20sc         S   s   |  j  d  d S(   Nt    i    (   t   split(   t   s(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   <lambda>   s    i   i   i   i    i   (   R&   RH   R+   R,   t   mapRI   t   int(   R5   R>   RN   RO   R   t   software_versiont   software_datet   options_listt   reservedt   minimize_romt   minimize_ram(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt	   decode_id   s    '*c         C   s   t  |  d k s t d  t j d | d   \ } } } } } } g  } | d } xz t d  D]l }	 t j d | d |	 d |	 d ! \ }
 } } |
 d @|
 d	 @|
 d
 @|
 d @f }
 | j |
 | | f  q` Wt |  f S(   NiZ   sB   Channel Summary Message should be 51 words total (90 byte message)s   <LhhHLLi   i   s   <HHHi   i   i   i   i   (   R&   RH   R+   R,   t   ranget   appendt   tuple(   R5   R>   RN   RO   RP   RU   t   gpswsRW   R   t   it   flagst   prnt   cno(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_channels   s    (
."c         C   s!  t  |  d k s t d  t j d | d   \ } } } } } } } }	 t d   | | | | | f  \ } } } } } g  }
 | d } xv t |	  D]h } t j d | d | d | d ! \ } } } t d	   | | f  \ } } |
 j | | | f  q Wt |
  | | | | | f f S(
   NiZ   sE   Visible Satellites Message should be 51 words total (90 byte message)s	   <LhhhhhhHi   c         S   s   t  |   d S(   Ng{Gz?(   RI   (   t   n(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyRy      s    s   <Hhhi   i   c         S   s   t  |   d t j S(   Ng;On?(   RI   RL   RM   (   R   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyRy      s    (   R&   RH   R+   R,   Rz   R   t   pushR   (   R5   R>   RN   RO   t   gdopt   pdopRr   t   vdopt   tdopt   numsatellitesR	   R   R   t   azit   elev(    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_satellites   s    .0
.c         C   s%   t  |  d k s t d  t  d  S(   Ni&   sJ   Differential GPS Status Message should be 25 words total (38 byte message)(   R&   RH   t   NotImplementedError(   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_dgps   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni`   sN   ECEF Position Status Output Message should be 54 words total (96 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_ecef   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni(  sH   Channel Measurement Message should be 154 words total (296 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_channelmeas   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni    sG   User-Settings Output Message should be 22 words total (32 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_usersettings   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni   sH   Built-In Test Results Message should be 20 words total (28 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_testresults   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni  sJ   Measurement Time Mark Message should be 253 words total (494 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_meastimemark   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni   sM   UTC Time Mark Pulse Output Message should be 20 words total (28 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_utctimemark   s    c         C   s%   t  |  d k s t d  t  d  S(   Ni   s^   Serial Port Communication Paramaters In Use Message should be 21 words total (30 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_serial  s    c         C   s%   t  |  d k s t d  t  d  S(   Ni   s?   EEPROM Update Message should be 10 words total (8 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_eepromupdate  s    c         C   s%   t  |  d k s t d  t  d  S(   Ni   s@   EEPROM Status Message should be 18 words total (24 byte message)(   R&   RH   R   (   R5   R>   (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   decode_eepromstatus
  s    (   R   R   R@   t   messagesR1   R'   R%   R?   R4   Ru   R   R   R   R   R   R   R   R   R   R   R   R   R   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyR   !   sh   

	<		'												(   t   __doc__R+   R.   RL   t   twisted.internetR    t   twisted.pythonR   R*   t
   ValueErrorR   t   ProtocolR   (    (    (    sB   /usr/lib/python2.7/dist-packages/twisted/protocols/gps/rockwell.pyt   <module>   s   $