# Copyright (c) 2021 Satlab A/S <satlab@satlab.com>
# SPDX-License-Identifier: GPL-3.0

# Constellation mappings from CCSDS 401.0-B

import math
from gnuradio import digital

M_SQRT1_2 = 1 / math.sqrt(2)


def ccsds_constellation_bpsk():
    return digital.constellation_bpsk().base()


def ccsds_constellation_qpsk():
    return digital.constellation_calcdist(
        [M_SQRT1_2 + M_SQRT1_2 * 1j,
         M_SQRT1_2 - M_SQRT1_2 * 1j,
        -M_SQRT1_2 + M_SQRT1_2 * 1j,
        -M_SQRT1_2 - M_SQRT1_2 * 1j],
        [0, 1, 2, 3],
        4, 1).base()


# 8PSK constellation (CCSDS 131.0-B-3)
def ccsds_constellation_8psk():
    return digital.constellation_calcdist(
        [M_SQRT1_2 + M_SQRT1_2 * 1j,
                 1 + 0j,
                -1 + 0j,
        -M_SQRT1_2 - M_SQRT1_2 * 1j,
                 0 + 1j,
         M_SQRT1_2 - M_SQRT1_2 * 1j,
        -M_SQRT1_2 + M_SQRT1_2 * 1j,
                 0 - 1j],
        [0, 1, 2, 3, 4, 5, 6, 7],
        8, 1).base()
