
    g                    B    d dl mZ d dlmZ ddlmZ ddZddZddZdS )    )annotations)datetime   )commonmsg0strmsg1t0int | datetimet1returnNone | tuple[float, float]c                (   t          j        |           dd         }t          j        |          dd         }t          |d                   }t          |d                   }|dk    r|dk    rn$|dk    r|dk    r	||}}||}}nt          d          t          j        |dd                   d	z  }t          j        |dd
                   d	z  }	t          j        |dd                   d	z  }
t          j        |dd
                   d	z  }d}d}t          j        d|z  d|
z  z
  dz             }t          ||dz  |z   z            }t          ||dz  |
z   z            }|dk    r|dz
  }|dk    r|dz
  }t          j        |          t          j        |          k    rdS ||k    rm|}t          j        |          }t          t          j        |          dz
  d          }t          j        |	|dz
  z  ||z  z
  dz             }d|z  ||z  |	z   z  }nl|}t          j        |          }t          t          j        |          dz
  d          }t          j        |	|dz
  z  ||z  z
  dz             }d|z  ||z  |z   z  }|dk    r|dz
  }||fS )ai  Decode airborne position from a pair of even and odd position message

    Args:
        msg0 (string): even message (28 hexdigits)
        msg1 (string): odd message (28 hexdigits)
        t0 (int): timestamps for the even message
        t1 (int): timestamps for the odd message

    Returns:
        (float, float): (latitude, longitude) of the aircraft
        N   r      z*Both even and odd CPR frames are required.   '      8         @<"h@;   <         ?i  h     )	r   hex2binintRuntimeErrorbin2intfloorfloatcprNLmax)r   r	   r
   r   mb0mb1oe0oe1cprlat_evencprlon_even
cprlat_odd
cprlon_oddair_d_lat_evenair_d_lat_oddjlat_evenlat_oddlatnlnimlons                         K/home/andy/.local/lib/python3.11/site-packages/pyModeS/decoder/bds/bds05.pyairborne_positionr9      s    .

rss
#C
.

rss
#C
c"g,,C
c"g,,C
axxC1HH	cQhhSRBGHHH .RU,,v5K.RU,,v5KBrE
++f4JBrE
++f4JNM 	R+%Z7#=>>A^q2v';<==HMQVj%89::G3c>#~~C- |Hg!6!666t 
Bww\#c""Q&**LQ/*r/ACGHHRxAF[01\#c""Q&**LQ/*r/ACGHHRxAFZ/0
SyyCi8O    msglat_refr#   lon_reftuple[float, float]c                   t          j        |           dd         }t          j        |dd                   dz  }t          j        |dd                   dz  }t          |d                   }|rdnd	}t          j        d
||z  z   |z
            }|||z   z  }	t          j        |	          |z
  }
|
dk    rd|
z  }nd}t          j        d
||z  z   |z
            }|||z   z  }|	|fS )a  Decode airborne position with only one message,
    knowing reference nearby location, such as previously calculated location,
    ground station, or airport location, etc. The reference position shall
    be within 180NM of the true position.

    Args:
        msg (str): even message (28 hexdigits)
        lat_ref: previous known latitude
        lon_ref: previous known longitude

    Returns:
        (float, float): (latitude, longitude) of the aircraft
    r   Nr   r   r   r   r   r   r   r   r   r   )r   r   r!   r   r"   r$   )r;   r<   r=   mbcprlatcprlonid_latr0   r3   r5   d_lonr6   r7   s                 r8   airborne_position_with_refrF   X   s    " 
		RSS	!B^Br"uI&&/F^Br"uI&&/FBrFA'HHxE 	S7U?*V344A
1v:
C	c		Q	B	AvvbS7U?*V344A
1v:
C8Or:   
None | intc                h   t          j        |           }||dk     s|dk    s|dk    rt          d| z            t          j        |           dd         }|dd         }|dk     r6|d	d
         dz   |d
d         z   }t          j        |          }|dk    r|S dS t          j        |          dz  S )z{Decode aircraft altitude

    Args:
        msg (str): 28 hexdigits string

    Returns:
        int: altitude in feet
    N	      r   z$%s: Not an airborne position messager         r      0igD
)?
@)r   typecoder    r   altituder!   )r;   tcr@   altbinaltcodealts         r8   rP   rP      s     
		B	zR!VVrRxx277ACGHHH			RSS	!B"XF	Bww1+#fQRRj0og&&'>>J 4~f%%//r:   N)
r   r   r	   r   r
   r   r   r   r   r   )r;   r   r<   r#   r=   r#   r   r>   )r;   r   r   rG   )
__future__r   r    r   r9   rF   rP    r:   r8   <module>rX      s    # " " " " "            G G G GT) ) ) )X0 0 0 0 0 0r:   