// --------------------------------------------------------------
#ifndef _RADIO_DEFORMATTER_HPP_
#define	_RADIO_DEFORMATTER_HPP_

#include <radio/radio_types.h>
#include <radio/cpx.h>
#include <cpp/radio/processor/src/Block.hpp>
#include "FrameDefs.hpp"
#include "Scrambler.hpp"


class DeFormatter : public Processor::Block
{
	enum State
	{
		Idle,
		Header,
		Data
	};

public:
	DeFormatter();
	virtual ~DeFormatter() = default;
	void process(uint8_t data);
	frame_statistics_t getStats();
	void resetStats();

	// Processor::Block
	void prepare() override;
	void process() override;

private:
	Scrambler m_scrambler;
	uint32_t m_dataCount;
	uint16_t m_sync_preamble;
	frame_hdr_t m_Hdr;
	uint8_t m_data[FRAME_NUM_BYTES_PER_FRAME];
	frame_statistics_t m_frameStats;
	State m_state;
	Processor::Buffer<uint8_t> *m_buf_in;
	Processor::Buffer<uint8_t> *m_buf_out;

	bool process_sync();
	bool process_header();
	bool process_data();
};

// --------------------------------------------------------------
#endif // _RADIO_DEFORMATTER_HPP_
