/*! Time-stamp: <@(#)ATBoardTunDVBSS2.cpp   07/05/2007 - 15:46:04   P.Hoogervorst>
*********************************************************************
*  @file   : ATBoardTunDVBSS2.cpp
*
*  Author  : P.Hoogervorst                              Date: 07/05/2007
*
*  Purpose : Implementation of methods for class 
*
*********************************************************************
* Version History:
*
* V 0.10  07/05/2007  BN : First Revision
*
*********************************************************************
*/

/**********************************************************************************************************/
// includes
#include "ATBoardTunDVBSS2.h"

/**********************************************************************************************************/
// defines

/**********************************************************************************************************/
// functions
// constructor
CATBoardTunDVBSS2::CATBoardTunDVBSS2(void)
{
}

// destructor
CATBoardTunDVBSS2::~CATBoardTunDVBSS2(void)
{
}


/*
 * Do the one time initialize and reset of the tuner. Is done once at startup.
 */
BOOL CATBoardTunDVBSS2::Init()
{
	// init tuner controller
	m_pAtBoard->DvbSource(SRC_INIT, NULL);

	return TRUE;
}

/*
 * Set the tuner.
 */
BOOL CATBoardTunDVBSS2::Set(u32					nFreq,
							u32					nSymbolRate,
							src_sec_tone_mode_t	LNBTone,
							src_sec_voltage_t	LNBVolt,
							BOOL				LNBHighVolt)
{
	dvb_frontend_parameters Info;

	// set LNB
	m_pAtBoard->DvbSource(SRC_ENABLE_HIGH_LNB_VOLTAGE, (void*)&LNBHighVolt);
	m_pAtBoard->DvbSource(SRC_SET_VOLTAGE, (void*)&LNBVolt);
	m_pAtBoard->DvbSource(SRC_SET_TONE, (void*)&LNBTone);
	
	// set parameters
	Info.frequency = nFreq;
	Info.u.qpsk.symbol_rate = nSymbolRate;

	// send parameters to device
	return m_pAtBoard->DvbSource(SRC_SET_FRONTEND, &Info);
}

/*
 * Get status from the tuner
 */
BOOL CATBoardTunDVBSS2::Get(BOOL &bInSync,
							BOOL &bCarrierDet,
							BOOL &bLock,
							s32 &nSignalStrength,
							s32 &nSnr,
							u32 &nBer,
							src_dvbs_mode_t &Mode,
							src_modulation_t &Modulation,
							src_code_rate_t &Fec,
							src_filter_rolloff_t &FiltRollOff,
							BOOL &bPilots,
							BOOL &bLongFrame,
							BOOL &bInversion)
{
	// set to defaults
	bInSync = FALSE;
	bCarrierDet = FALSE;
	bLock = FALSE;
	nSignalStrength = 0;
	nSnr = 0;
	nBer = 0;
	Mode = DVBS_MODE_S;
	Modulation = QPSK;
	Fec = FEC_1_2;
	FiltRollOff = FLT_ALPHA_35;
	bPilots = FALSE;
	bLongFrame = FALSE;
	bInversion = FALSE;
	
	// get status
	dvb_frontend_parameters Info;
	if (!m_pAtBoard->DvbSource(SRC_GET_FRONTEND, &Info))
		return FALSE;

	if (Info.u.qpsk.lock_status & SRC_HAS_SYNC)
		bInSync = TRUE;
	else
		bInSync = FALSE;
	
	if (Info.u.qpsk.lock_status & SRC_HAS_CARRIER)
		bCarrierDet = TRUE;
	else
		bCarrierDet = FALSE;
	
	if (Info.u.qpsk.lock_status & SRC_HAS_LOCK)
		bLock = TRUE;
	else
		bLock = FALSE;

	Mode = Info.u.qpsk.dvbs_mode;
	Modulation = Info.u.qpsk.modulation;
	Fec = Info.u.qpsk.fec_inner;
	FiltRollOff = Info.u.qpsk.filter_rolloff;
	bPilots = Info.u.qpsk.pilots_on;
	bLongFrame = Info.u.qpsk.longframe_on;
	bInversion = Info.inversion;
	nSignalStrength = Info.u.qpsk.power;
	nSnr = Info.u.qpsk.snr;
	nBer = Info.u.qpsk.BER;

	return TRUE;
}
