/* -*- c++ -*- */
/* 
 * Copyright 2018 Jay Arrowfield.
 * 
 * This is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 3, or (at your option)
 * any later version.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this software; see the file COPYING.  If not, write to
 * the Free Software Foundation, Inc., 51 Franklin Street,
 * Boston, MA 02110-1301, USA.
 */

#ifndef INCLUDED_JAY_BIT_SLICER_IMPL_H
#define INCLUDED_JAY_BIT_SLICER_IMPL_H

#include <jay/bit_slicer.h>

namespace gr
{
namespace jay
{

class bit_slicer_impl : public bit_slicer
{
	private:
	int m_sampleRate;
	int m_samplesPerSym;
        int m_count;
        bool m_isSignal;
	float m_baudRate;
        float m_kLoopFilter;
        float m_kThreshold;
		int m_doPrintPackets;
        float m_vmin;
        float m_vmax;
        float m_v_sig;
        float m_dc_corr;
		float m_agc_gain;
        float m_lag_accu;
        float m_id_accu;
        int m_id_bit;
        int m_bitZeroCross;
        float m_i;
        int m_gapDistance;
        int m_gapCounter;
        int m_gapCounterEnable;
        int m_packetCounter;
        int m_bitCounter;
        uint64_t m_sampleCounter;
        int m_bits[4096];
        
        FILE *m_pFile_y;
        FILE *m_pFile_bits;
        
        void bitProcessGap(int bitChg);
        void bitRecord(int bit);
        void bitsPrint();
        bool start() override;
        bool stop() override;
        
	public:
	bit_slicer_impl(int sampleRate, int samplesPerSym, float kLoopFilter, float kThreshold, int numGapBits, int doPrintPackets);
	~bit_slicer_impl();

	// Where all the action really happens
	void forecast (int noutput_items, gr_vector_int &ninput_items_required);

	int general_work(int noutput_items,
	gr_vector_int &ninput_items,
	gr_vector_const_void_star &input_items,
	gr_vector_void_star &output_items);
};

} // namespace jay
} // namespace gr

#endif /* INCLUDED_JAY_BIT_SLICER_IMPL_H */

