#include "PingPongTable.h"
#include "NDTSError.h"

using namespace NDTS::RS2A;

PingPongTable::PingPongTable(int physicalElements, 
			   int apertureSize, 
			   int pitchMultiplier,
			   bool doPingPong
			   ) 
{
	this->physicalElements = physicalElements; 
	this->apertureSize = apertureSize;
	this->pitchMultiplier = pitchMultiplier;
	this->doPingPong = doPingPong;
	activeElements = (physicalElements - apertureSize + 1);
	if(pitchMultiplier == 0)
		pitchMultiplier = 1;
	aScansPerBScan = (activeElements - 1) / pitchMultiplier + 1;

/*	NDTS_LogLine(NDTS_LLErr, "el %d ap %d mult %d active el %d a per b %d",
	this->physicalElements, 
	this->apertureSize, 
	this->pitchMultiplier, 
	activeElements, 
	aScansPerBScan);
*/
}

PingPongTable::~PingPongTable()
{

}

int PingPongTable::getAScansPerBScan()
{
	return aScansPerBScan;
}

int PingPongTable::getMaximumAScansPerBScan()
{
	return activeElements;
}


unsigned long PingPongTable::getSequencePosition(unsigned long index)
{
	// No ping pong - this is quite simple
	return (index * pitchMultiplier) + apertureSize / 2;
}
unsigned long PingPongTable::getEffectivePosition(unsigned long index)
{
	// Effective position is only changed when ping pong is enabled.
	// Array flipping acts at a lower level in RQ.dll
	return index;
}

