#ifndef GRIFO_SYNTH_IF_H
#define GRIFO_SYNTH_IF_H

#include "grifo_ctrlink.h"

#include <stdint.h>

namespace grifo_fw
{

enum synth_msg_k
{
    synth_freq_max_values=121,

    synth_req_lsb_hz = 4
};


template<typename T_> unsigned int synth_frequency_trunc_hz(T_ f)
{
    unsigned int x=static_cast<unsigned int>(f/static_cast<unsigned int>(synth_req_lsb_hz)); //should work with float wihout warnings
    return x;
}

template<typename T_> unsigned int synth_frequency_round_hz(T_ f)
{   //Note: this work only if synth_req_lsb_hz is an integer
    unsigned int k=static_cast<unsigned int>(synth_req_lsb_hz);
    unsigned int x=static_cast<unsigned int>((f+(k-1))/k);
    return x;
}

extern int synth_append_status_request(ctrlink_blob_t* ld);

extern int synth_append_frequency_operative_message(ctrlink_blob_t* ld, unsigned int num_values, const unsigned int* frq /*[num_values]*/, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);
extern int synth_append_frequency_operative_message_ext(ctrlink_blob_t* ld, unsigned int num_values, unsigned int cfg, const unsigned int* frq /*[num_values]*/, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);

extern uint32_t* synth_allocate_frequency_operative_message(ctrlink_blob_t* ld, unsigned int num_values, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);
extern uint32_t* synth_allocate_frequency_operative_message_ext(ctrlink_blob_t* ld, unsigned int num_values, unsigned int cfg, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);

extern int synth_append_frequency_asynch_message(ctrlink_blob_t* ld, unsigned int frq);


extern int synth_append_frequency_sel_ew_operative_message(ctrlink_blob_t* ld, unsigned int num_values, const unsigned int* frq /*[num_values]*/, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);
extern uint32_t* synth_allocate_frequency_sel_ew_operative_message(ctrlink_blob_t* ld, unsigned int num_values, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);
extern int synth_append_frequency_sel_ew_asynch_message(ctrlink_blob_t* ld, unsigned int frq);

extern int synth_append_control_opeative_message(ctrlink_blob_t* ld, unsigned int cal, unsigned int ew_rdr, ctrlink_pingpong_t pingpong=ctrlink_pingpong_auto);
extern int synth_append_control_asynch_message(ctrlink_blob_t* ld, unsigned int cal, unsigned int ew_rdr);

}//namespace

#endif // GRIFO_SYNTH_IF_H
