コード例 #1
0
ファイル: df17.py プロジェクト: na5ss/mlat-client
def make_position_frame(metype, addr, elat, elon, ealt, oddflag):
    """Create single DF17 position frame"""

    frame = bytearray(14)

    frame[0] = (17 << 3) | (5)       # DF, CA
    frame[1] = (addr >> 16) & 255    # AA
    frame[2] = (addr >> 8) & 255     # AA
    frame[3] = addr & 255            # AA
    frame[4] = (metype << 3)         # ME type, status 0, SAF 0
    frame[5] = (ealt >> 4) & 255     # Altitude (MSB)
    frame[6] = (ealt & 15) << 4      # Altitude (LSB)
    if oddflag:
        frame[6] |= 4                # CPR format
    frame[6] |= (elat >> 15) & 3     # CPR latitude (top bits)
    frame[7] = (elat >> 7) & 255     # CPR latitude (middle bits)
    frame[8] = (elat & 127) << 1     # CPR latitude (low bits)
    frame[8] |= (elon >> 16) & 1     # CPR longitude (high bit)
    frame[9] = (elon >> 8) & 255     # CPR longitude (middle bits)
    frame[10] = elon & 255           # CPR longitude (low bits)

    # CRC
    c = _modes.crc_residual(frame)
    frame[11] = (c >> 16) & 255
    frame[12] = (c >> 8) & 255
    frame[13] = c & 255

    return frame
コード例 #2
0
ファイル: df17.py プロジェクト: na5ss/mlat-client
def make_velocity_frame(addr, nsvel, ewvel, vrate):
    """Create a DF17 airborne velocity frame"""

    supersonic = (nsvel is not None and abs(nsvel) > 1000) or (ewvel is not None and abs(ewvel) > 1000)

    e_ns = encode_velocity(nsvel, supersonic)
    e_ew = encode_velocity(ewvel, supersonic)
    e_vr = encode_vrate(vrate)

    frame = bytearray(14)

    frame[0] = (17 << 3) | (5)       # DF, CA
    frame[1] = (addr >> 16) & 255    # AA
    frame[2] = (addr >> 8) & 255     # AA
    frame[3] = addr & 255            # AA
    frame[4] = (19 << 3)             # ES type 19, airborne velocity
    if supersonic:
        frame[4] |= 2                # subtype 2, ground speed, supersonic
    else:
        frame[4] |= 1                # subtype 1, ground speed, subsonic

    frame[5] = (e_ew >> 8) & 7       # intent change 0, IFR 0, NUCr 0, E/W velocity top bits
    frame[6] = (e_ew & 255)          # E/W velocity low bits
    frame[7] = (e_ns >> 3) & 255     # N/S velocity top bits
    frame[8] = (e_ns & 7) << 5       # N/S velocity low bits
    frame[8] |= 16                   # vertical rate source = baro
    frame[8] |= (e_vr >> 6) & 15     # vertical rate top bits
    frame[9] = (e_vr & 63) << 2      # vertical rate low bits
    frame[10] = 0                    # GNSS/Baro alt offset, no data

    # CRC
    c = _modes.crc_residual(frame)
    frame[11] = (c >> 16) & 255
    frame[12] = (c >> 8) & 255
    frame[13] = c & 255

    return frame