// $Header: https://oberon.oapd.inaf.it/shins/trunk/shins/src/tiptilt_ctrl/bcu/Interface/Sharknir/Bcu/SharknirBcuCcdDiagnosticRecord.h 961 2018-10-30 11:15:19Z depa $
#pragma once

// #include "basda/service/bcu/worker/ArgosBcuDiagnosticRecordHeader.h"
#include "tiptilt_ctrl/bcu/Interface/Sharknir/Bcu/SharknirBcuDiagnosticRecordHeader.h"

#include <Basda/Microgate/Mgp/ByteBuffer.h>

#include <boost/cstdint.hpp>
#include <boost/static_assert.hpp>

#include <string>
#include <vector>

namespace Sharknir { namespace Bcu {

struct BaseCcdDiagnosticRecord
{
    enum {
        N_CCD_CHANNELS= 132,
        N_CCD_LINES= 132,
        N_CCD_CAMEX= 4,
        N_PIXELS= N_CCD_LINES*N_CCD_CHANNELS*N_CCD_CAMEX,
        CCD_FRAME_HEADER_SIZE_IN_DWORD= 8,
        TRUNCATED_CCD_FRAME_HEADER_SIZE_IN_DWORD= 4
    };

    BOOST_STATIC_ASSERT(CCD_FRAME_HEADER_SIZE_IN_DWORD >
                                    TRUNCATED_CCD_FRAME_HEADER_SIZE_IN_DWORD);
    typedef uint16_t Pixel;

    static const uint16_t width;
    static const uint16_t height;
};


struct BuiltInAdcCcdDiagnosticRecord : public BaseCcdDiagnosticRecord
{
    DiagnosticRecordHeader header;
    Pixel pixels[N_PIXELS];
    DiagnosticRecordFooter footer;
};


struct OptAdcCcdDiagnosticRecord : public BaseCcdDiagnosticRecord
{
    DiagnosticRecordHeader header;
    uint32_t ccdFrame[TRUNCATED_CCD_FRAME_HEADER_SIZE_IN_DWORD];
    Pixel pixels[N_PIXELS];
};


typedef BuiltInAdcCcdDiagnosticRecord SharknirBcuCcdDiagnosticRecord;

BOOST_STATIC_ASSERT(139424 == sizeof(SharknirBcuCcdDiagnosticRecord));

typedef std::vector<float> SeqFloat;
SeqFloat getPixelsAsFloats(const Basda::Microgate::ByteBufferPtr& b);

std::string
getRawPixelFloatsAsString(const Basda::Microgate::ByteBufferPtr& b);


bool isCcdDiagnosticRecordBroken(
        const BuiltInAdcCcdDiagnosticRecord* const);
bool isCcdDiagnosticRecordBroken(
        const OptAdcCcdDiagnosticRecord* const);

bool hasSanityCheck(BuiltInAdcCcdDiagnosticRecord);
bool hasSanityCheck(OptAdcCcdDiagnosticRecord);

}
}
