
    g                     B    d dl mZ dedefdZdedefdZdedefdZdS )   )commonmsgreturnc                 H   t          j        |           dk    rt          d| z            t          j        |           dd         }t          j        |dd                   }|dk    rt          d          t          j        |dd	                   }|d
k    r|d
k    rdS dS )a^  Check if the aircraft is reporting an emergency.

    Non-emergencies are either a subtype of zero (no information) or
    subtype of one and a value of zero (no emergency).
    Subtype = 2 indicates an ACAS RA broadcast, look in BDS 3,0

    :param msg: 28 bytes hexadecimal message string
    :return: if the aircraft has declared an emergency
       3%s: Not an airborne status message, expecting TC=28    N         1%s: Emergency message is ACAS-RA, not implemented      TF)r   typecodeRuntimeErrorhex2binbin2intr   mbsubtypeemergency_states       K/home/andy/.local/lib/python3.11/site-packages/pyModeS/decoder/bds/bds61.pyis_emergencyr   
   s     sr!!ACG
 
 	
 
		RSS	!BnR!W%%G!||NOOOnR"X..O!||1,,tu    c                     t          j        |           dd         }t          j        |dd                   }|dk    rt          d          t          j        |dd                   }|S )au  Decode aircraft emergency state.

    Value   Meaning
    -----   -----------------------
    0       No emergency
    1       General emergency
    2       Lifeguard/Medical
    3       Minimum fuel
    4       No communications
    5       Unlawful communications
    6-7     Reserved

    :param msg: 28 bytes hexadecimal message string
    :return: emergency state
    r	   Nr
   r   r   r   r   )r   r   r   r   r   s       r   r   r   '   sh    " 
		RSS	!BnR!W%%G!||NOOOnR"X..Or   c                     t          j        |           dk    rt          d| z            t          j        |           }|dd         }t          j        |          }|S )zDecode squawk code.

    Emergency value 1: squawk 7700.
    Emergency value 4: squawk 7600.
    Emergency value 5: squawk 7500.

    :param msg: 28 bytes hexadecimal message string
    :return: aircraft squawk code
    r   r   +   8   )r   r   r   r   squawk)r   msgbinidcoder   s       r   emergency_squawkr"   B   sg     sr!!ACG
 
 	
 ^C  F BrE]F]6""FMr   N) r   strboolr   intr   r"    r   r   <module>r(      s         c d    :     6# #      r   