id: variable_constellation
label: Constellation Object
category: Modulators
flags: [ show_id, python, cpp ]

parameters:
-   id: type
    label: Constellation Type
    dtype: enum
    options: [calcdist, bpsk, qpsk, dqpsk, 8psk, 16qam]
    option_labels: [Variable Constellation, BPSK, QPSK, DQPSK, 8PSK, 16QAM]
-   id: sym_map
    label: Symbol Map
    dtype: int_vector
    default: '[0, 1, 3, 2]'
    hide: ${ ( 'none' if str(type) == "calcdist" else 'all') }
-   id: const_points
    label: Constellation Points
    dtype: complex_vector
    default: '[-1-1j, -1+1j, 1+1j, 1-1j]'
    hide: ${ ( 'none' if str(type) == "calcdist" else 'all') }
-   id: rot_sym
    label: Rotational Symmetry
    dtype: int
    default: '4'
    hide: ${ ( 'none' if str(type) == "calcdist" else 'all') }
-   id: dims
    label: Dimensionality
    dtype: int
    default: '1'
    hide: ${ ( 'none' if str(type) == "calcdist" else 'all') }
-   id: normalization
    label: Normalization Type
    dtype: raw
    default: digital.constellation.AMPLITUDE_NORMALIZATION
    options: [digital.constellation.NO_NORMALIZATION, digital.constellation.POWER_NORMALIZATION, digital.constellation.AMPLITUDE_NORMALIZATION]
    option_labels: [None, Power, Amplitude]
    hide: ${ ( 'none' if str(type) == "calcdist" else 'all') }
-   id: precision
    label: Soft Decisions Precision
    dtype: int
    default: '8'
-   id: npwr
    label: Noise Power
    dtype: float
    default: '1.0'
    hide: part
-   id: soft_dec_lut
    label: Soft Decisions LUT
    dtype: raw
    default: None
    hide: ${ ('part' if str(soft_dec_lut) == 'None' else 'none') }

value: ${ digital.constellation_calcdist(const_points, sym_map, rot_sym, dims, normalization) if (str(type) == "calcdist") else getattr(digital,'constellation_'+str(type))()  }


templates:
    imports: from gnuradio import digital
    var_make: |-
        % if str(type) == "calcdist":
        self.${id} = ${id} = digital.constellation_calcdist(${const_points}, ${sym_map},
        ${rot_sym}, ${dims}, ${normalization}).base()
        % else:
        self.${id} = ${id} = digital.constellation_${type}().base()
        % endif
        self.${id}.set_npwr(${npwr})
        % if str(soft_dec_lut).lower() == '"auto"' or str(soft_dec_lut).lower() == "'auto'":
        self.${id}.gen_soft_dec_lut(${precision})
        % elif str(soft_dec_lut) != "None":
        self.${id}.set_soft_dec_lut(${soft_dec_lut}, ${precision})
        % endif

cpp_templates:
    includes: ['#include <gnuradio/digital/constellation.h>']
    declarations: 'digital::constellation::sptr ${id};'
    var_make: |-
        std::vector<int> sym_map = {${str(sym_map)[1:-1]}};
        std::vector<gr_complex> const_points = {${str(const_points)[1:-1]}};
        % if str(type) == "calcdist":
        this->${id} = digital::constellation_calcdist(const_points, sym_map,
        ${rot_sym}, ${dims}).base();
        % else:
        this->${id} = ${id} = digital::constellation_${type}().base();
        % endif
        this->${id}.set_npwr(${npwr});
        % if str(soft_dec_lut).lower() == '"auto"' or str(soft_dec_lut).lower() == "'auto'":
        this->${id}.gen_soft_dec_lut(${precision});
        % elif str(soft_dec_lut) != "None":
        this->${id}.set_soft_dec_lut(${soft_dec_lut}, ${precision});
        % endif
    link: ['gnuradio::gnuradio-digital']

file_format: 1
