#include "grifo_aesa_fw_if.h"
#include "aesa_cmd_data.h"

using namespace grifo_fw;
using namespace aesa;

beam_calculation_t grifo_fw::BeamData::beam_data={9500,9500,0,0,0,0,0,0,0,0,0,0,0,0,188,255};
rfif_mode_command_t grifo_fw::RfifMode::rfif_mode={rfif_operative_mode,guard_sel_1,off,tx_open,up,up,up,up,off,off,0,9500,9500};

beam_calculation_t* BeamData::get_beam_data()
{
    return &beam_data;
}

void BeamData::set_frequency(uint16_t freq)
{
    beam_data.tx_freq=freq;
    beam_data.rx_freq=freq;
}

void BeamData::set_frequency(uint16_t tx_freq, uint16_t rx_freq)
{
    beam_data.tx_freq=tx_freq;
    beam_data.rx_freq=rx_freq;
}

void BeamData::set_position(float u, float v)
{
    beam_data.tx_u=u;
    beam_data.tx_v=v;
    beam_data.rx_u=u;
    beam_data.rx_v=v;
}

void BeamData::set_position(float tx_u, float tx_v, float rx_u, float rx_v)
{
    beam_data.tx_u=tx_u;
    beam_data.tx_v=tx_v;
    beam_data.rx_u=rx_u;
    beam_data.rx_v=rx_v;
}

void BeamData::set_tx_ctrl_state_idx(uint16_t index)
{
    beam_data.tx_ctrl_state_index=index;
}

void BeamData::set_rx_ctrl_state_idx(uint16_t index)
{
    beam_data.rx_ctrl_state_index=index;
}

void BeamData::set_tx_enable_pattern(uint8_t index)
{
    beam_data.tx_enable_pattern_index=index;
}

void BeamData::set_rx_enable_pattern(uint8_t index)
{
    beam_data.rx_enable_pattern_index=index;
}

void BeamData::set_guard_position(float u, float v)
{
    beam_data.guard_rx_u=u;
    beam_data.guard_rx_v=v;
}

void BeamData::set_guard_ctrl_state_idx(uint16_t index)
{
    beam_data.guard_rx_ctrl_state_index=index;
}

void BeamData::set_guard_enable_pattern(uint8_t index)
{
    beam_data.guard_rx_enable_pattern_index=index;
}

void BeamData::set_sync_divisor(uint16_t divisor)
{
    beam_data.sync_divisor=divisor;
}

void BeamData::set_duty_ratio(uint8_t duty_r)
{
    beam_data.duty_ratio=duty_r;
}

void BeamData::initialize()
{
    beam_data.tx_freq=9500;
    beam_data.rx_freq=9500;
    beam_data.tx_u=0;
    beam_data.tx_v=0;
    beam_data.rx_u=0;
    beam_data.rx_v=0;
    beam_data.tx_ctrl_state_index=0;
    beam_data.tx_enable_pattern_index=0;
    beam_data.rx_ctrl_state_index=0;
    beam_data.rx_enable_pattern_index=0;
    beam_data.guard_rx_u=0;
    beam_data.guard_rx_v=0;
    beam_data.guard_rx_ctrl_state_index=0;
    beam_data.guard_rx_enable_pattern_index=0;
    beam_data.sync_divisor=188;
    beam_data.duty_ratio=255;
}

rfif_mode_command_t* RfifMode::get_rfif_mode()
{
    return &rfif_mode;
}

void RfifMode::set_mode(rfif_mode_t mode)
{
    rfif_mode.mode=mode;
}

void RfifMode::set_guard_sel(rfif_guard_sel_t sel)
{
    rfif_mode.guard_sel=sel;
}

void RfifMode::set_radiation(off_on_t rad)
{
    rfif_mode.radiation_on=rad;
}

void RfifMode::set_tx_sample(tx_sample_t tx_sample)
{
    rfif_mode.tx_sample=tx_sample;
}

void RfifMode::set_tx_rx_guard_sel(up_down_t sel)
{
    rfif_mode.tx_rx_guard_sel=sel;
}

void RfifMode::set_guard_cal_sel(up_down_t sel)
{
    rfif_mode.guard_cal_sel=sel;
}

void RfifMode::set_cal_sel_a(up_down_t sel)
{
    rfif_mode.cal_sel_a=sel;
}

void RfifMode::set_cal_sel_b(up_down_t sel)
{
    rfif_mode.cal_sel_b=sel;
}

void RfifMode::set_detector(off_on_t det)
{
    rfif_mode.detector_on_off=det;
}

void RfifMode::set_amp_cal(off_on_t amp_cal)
{
    rfif_mode.amp_cal=amp_cal;
}

void RfifMode::set_attenuator(uint8_t atten)
{
    rfif_mode.attenuator=atten;
}

void RfifMode::set_frequency(uint16_t freq)
{
    rfif_mode.tx_frequency=freq;
    rfif_mode.rx_frequency=freq;
}

void RfifMode::set_frequency(uint16_t tx_freq, uint16_t rx_freq)
{
    rfif_mode.tx_frequency=tx_freq;
    rfif_mode.rx_frequency=rx_freq;
}

void RfifMode::initialize()
{
    rfif_mode.mode             = rfif_operative_mode;
    rfif_mode.guard_sel        = guard_sel_1;
    rfif_mode.radiation_on     = off;
    rfif_mode.tx_sample        = tx_open;
    rfif_mode.tx_rx_guard_sel  = up;
    rfif_mode.guard_cal_sel    = up;
    rfif_mode.cal_sel_a        = up;
    rfif_mode.cal_sel_b        = up;
    rfif_mode.detector_on_off  = off;
    rfif_mode.amp_cal          = off;
    rfif_mode.attenuator       = 0;
    rfif_mode.tx_frequency     = 9500;
    rfif_mode.rx_frequency     = 9500;
}
