/*
 * grifo_detector_if.cpp
 *
 */


#include "grifo_fw_blob.h"
#include "grifo_detector_if.h"

namespace grifo_fw
{

class detector_blob_t: public grifo_fw_blob_typed_t<detector_raw_if_t, 0x44455445/*="DETE"*/>
{
};

detector_blob_t* det_default_blob__;

}


grifo_fw::detector_raw_if_t* grifo_fw::detector_blob_payload(const grifo_fw::detector_blob_t* b)
{
    if (b==0)
        b=det_default_blob__;

    return &const_cast<grifo_fw::detector_blob_t*>(b)->payload;
}

void grifo_fw::detector_initialize_raw_default_blob(void* raw_memory)
{
    grifo_fw::detector_blob_t* b=reinterpret_cast<grifo_fw::detector_blob_t*>(raw_memory);
    b->initialize();

    b->payload.settings.sett.mof=detector_raw_if_t::mof_non_coherent;

    for(unsigned int i=0; i<detector_raw_if_t::num_ph_vectors; ++i)
    {
        //b->payload.ph_vectors[i][0]=i+1;
        for(unsigned int j=1; j<detector_raw_if_t::num_ph_channes; ++j)
        {
        }
    }
    for(unsigned int i=0; i<detector_raw_if_t::max_fir_set; ++i)
    {
        b->payload.post_filter[i].coeff[0]=1;
        b->payload.pre_filter[i].coeff[0]=1;

        for(unsigned int j=1; j<detector_raw_if_t::max_fir_len; ++j)
        {
            b->payload.post_filter[i].coeff[j]=0;
            b->payload.pre_filter[i].coeff[j]=0;
        }
    }

    b->header.work_size=(sizeof b->payload.settings)/4;
    det_default_blob__=b;
}

void grifo_fw::detector_enable_full_programming(bool enable)
{
    grifo_fw::detector_blob_t* b=grifo_fw::detector_get_default_blob();

    if (enable)
        b->header.work_size=(sizeof b->payload)/4;
    else
        b->header.work_size=(sizeof b->payload.settings)/4;
}

grifo_fw::detector_blob_t* grifo_fw::detector_get_default_blob()
{
    return det_default_blob__;
}

grifo_fw::detector_raw_if_t* grifo_fw::detector_get_default_if()
{
    return detector_blob_payload(0);
}


unsigned int grifo_fw::detector_output_frquency_mhz()
{
    grifo_fw::detector_raw_if_t* p=grifo_fw::detector_get_default_if();
    return detector_output_frquency_mhz(static_cast<grifo_fw::detector_raw_if_t::mof_t>(p->settings.sett.mof));

}
unsigned int grifo_fw::detector_output_frquency_mhz(grifo_fw::detector_raw_if_t::mof_t mof)
{
    switch(mof)
    {
        case detector_raw_if_t::mof_pass:
            return detector_raw_if_t::FS_1;

        case detector_raw_if_t::mof_non_coherent:
        default:
            return detector_raw_if_t::FS_1;
    }
}

unsigned int grifo_fw::detector_doppler_frequency_convert_hz(unsigned long hz)
{
    float fmhz=float(hz)/10000000;
    fmhz=fmhz/detector_raw_if_t::FS_2;
    return static_cast<unsigned int>(fmhz);
}


