/*******************************************************************************
*                                                                              *
* Société de Transports de Montréal.                                    	   *
* 2012 - 2013                                                                        *
*                                                                              *
* Projet Zones Tests                                                           *
*                                                                              *
*                                                                              *
*                                                                              *
*******************************************************************************/
/*
	Description:
	Classe instantiable d'une sonde lazer simulée.
	
*/

/* ************************************************************************** */
/* Revision:
### YYYMMDD JFM
	Verision d'origine.
	
### YYYYMMDD Description du besoin ou du bug
	Description du changement.
 */

/* ************************************************************************** */

#include "SimulatorLazerProbe.h"
#include "AbstractLazerProbeMgr.h"
#include "GlobalDefine.h"

CSimulatorLazerProbe::CSimulatorLazerProbe(unsigned int ProbeID, unsigned int ProbeType)
{
	mProbeID = ProbeID;
	mProbeType = ProbeType;
	mData = 100;
    mProbeAlive = true;
}

CSimulatorLazerProbe::~CSimulatorLazerProbe()
{

}

unsigned int CSimulatorLazerProbe::OpenPort(QString PortName)
{
	mPortName = PortName;
	return LAZERPROBES_MGR_RET_OK;
}

unsigned int CSimulatorLazerProbe::GetType()
{
	return mProbeType;
}

QString CSimulatorLazerProbe::GetPortName()
{
	return mPortName;
}

unsigned int CSimulatorLazerProbe::GetID()
{
	return mProbeID;
}

unsigned int CSimulatorLazerProbe::StartAcquisition()
{
	return LAZERPROBES_MGR_RET_OK;
}

unsigned int CSimulatorLazerProbe::StopAcquisition()
{
	return LAZERPROBES_MGR_RET_OK;
}

unsigned int CSimulatorLazerProbe::GetLastData()
{
	unsigned int temp;

//	mMutex.lock();
//	temp = mData;
//	mMutex.unlock();


	mRdWrLock.lockForRead();
	temp = mData;
	mRdWrLock.unlock();

	return temp;
}

unsigned int CSimulatorLazerProbe::SetData(unsigned int data)
{
	mRdWrLock.lockForWrite();
	mData = data;
	mRdWrLock.unlock();

	emit NewProbeData(data,mProbeType);

	return data;
}

unsigned int CSimulatorLazerProbe::FlushProbeData()
{
	return RET_OK;
}

bool CSimulatorLazerProbe::IsProbeAlive()
{
    bool alive;
    mRdWrLock.lockForRead();
    alive = mProbeAlive;
    mRdWrLock.unlock();

    return alive;
}

unsigned int CSimulatorLazerProbe::SetProbeAlive()
{
    mRdWrLock.lockForWrite();
    mProbeAlive = true;
    mRdWrLock.unlock();
    return RET_OK;
}

unsigned int CSimulatorLazerProbe::SetProbeDead()
{
    mRdWrLock.lockForWrite();
    mProbeAlive = false;
    mRdWrLock.unlock();
    return RET_OK;
}
