// --------------------------------------------------------------
#ifndef _RADIO_FORMATTER_HPP_
#define	_RADIO_FORMATTER_HPP_

#include <radio/radio_types.h>
#include <radio/cpx.h>
#include "FrameDefs.hpp"
#include "Scrambler.hpp"

class IFormatter
{
public:
	IFormatter() {}
	virtual ~IFormatter() {}
	virtual void onFrame(void *pFrame, uint32_t size) = 0;
};

class Formatter
{
public:
	Formatter(IFormatter *pFrameHandler);
	~Formatter();
	void process(void *pData, uint32_t len);
	frame_statistics_t getStats();
	void resetStats();

private:
	Scrambler m_scrambler;
	IFormatter *m_pFrameHandler;
	frame_t m_frame;
	uint32_t m_dataCount;
	uint32_t m_idleCount;
	frame_statistics_t m_frameStats;
	void process_idle(uint32_t len);
	void process_data(uint8_t *pData, uint32_t len);
	void commit(frame_type frameType, uint32_t m_dataCount);
};

class IData
{
public:
	IData() {}
	virtual ~IData() {}
	virtual void onData(data_t data) = 0;
	virtual void onReset() = 0;
};

class IDeFormatter
{
public:
	IDeFormatter() {}
	virtual ~IDeFormatter() {}
	virtual void onData(void *pData, uint32_t size) = 0;
};

class DeFormatter : public IData
{
public:
	DeFormatter(IDeFormatter *pDataHandler);
	~DeFormatter();
	void process(uint8_t data);
	frame_statistics_t getStats();
	void resetStats();

private:
	IDeFormatter *m_pDataHandler;
	Scrambler m_scrambler;
	uint32_t m_dataCount;
	frame_t m_frame;
	frame_statistics_t m_frameStats;
	bool m_enable;
	void onData(data_t data) override; 
	void onReset() override;
};

// --------------------------------------------------------------
#endif // _RADIO_FORMATTER_HPP_
