Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Tutorial #4: torn

Code Block
breakoutModewide
languagec
//---------------------------------------------------------
//            Main
//---------------------------------------------------------
//  Main function:
//		- Hypothesis: IP communication with ACE
//      - Use aceOut from Agnos tutorials
//
//  Visibility: Public
//  Hypothesis: --
//  Reference: --
//
int main(int argc, char** argv)
{
	// Communication
	int port, length;
	char address[50]="";
	// Trace for debugging
	char tmp[1000]="";

	// Get Communication parameters from ini file
	xgpiIniSetFilename("agnos.ini");
	xgpiIniGetString("COM", "Address", 50, address, &length);
	xgpiIniGetNumeric("COM", "Port", &port);

	// Initialize ACE
	// Initialize generic communication interface
	assert(tcpInit(0) == TCP_NO_ERROR);
	// Create server and client
	assert(comtcpOpen(&gACEServerCOMTCP, TCP_SERVER, 0, port) == COM_NO_ERROR);
	assert(comtcpOpen(&gACEClientCOMTCP, TCP_CLIENT, address, 1979) == COM_NO_ERROR);
	// Set ACE with server and client
	aceInitializeCommunication(&gACEServerCOMTCP.com,&gACEClientCOMTCP.com);

	// Set up ACE's options
	aceSetUIDisplay(bTRUE);
	// Activate SDK to access to ACE services
	aceSetMode(pmSDK);

	aceOut("Training Session - BEGIN\n");

	char* parameters;

	// Initialize GPI
	// This is platform dependent. On Kizis AVT, this set PCSC readers' name from agnos.ini
	gpiMain(0,&parameters);


	typedef struct {
		tCounter 		mDate;
		tCounter 		mTime;
		unsigned int 	mUN;
	} tTestTorn;

	unsigned long ramSize=0;
	tTestTorn* torn=0;
	tByte *pRAM = 0;
	tByte i;
	tWord len = 0, _FF01Value = 0, startData = 0;
	tByte gData[1000]="";

	gpiGetPrivateScratchPAD(MASTERCARD_PAYPASS,&pRAM,&ramSize);

	sprintf(tmp,"Scratch PAD Size %lu\n",ramSize);
	aceOut(tmp);

	torn = (tTestTorn*)pRAM;

	for(i = 0; i < 20; i++)
	{
		setDate(&torn[i].mDate,&torn[i].mTime);
		gpiGetRandomNumber(&torn[i].mUN,256);
		sprintf(tmp,"Torn %i UN %.2X Date: %lu Time: %lu\n",i,torn[i].mUN,torn[i].mDate,torn[i].mTime);
		aceOut(tmp);
		gpiSleep(500);
	}


	// Send DD signal

	tSignal signal;

	aceSetSignal(bTRUE); // Activate signal in ACE
	aceSetDigitalSignal(bTRUE); // Use digital signal instead of legacy strings
	aceGetSignal(&signal); // Get ACE signal services
	pmwSetSignal(&signal); // Set AgnosMW accordingly

	// Init indexes
	len = 0;
	_FF01Value = 0;
	startData = 0;
	gpiMemSet(gData,0x00,sizeof(gData));

	// Prepare DD
	gData[len++] = 0xFF;
	gData[len++] = 0x01;
	gData[len++] = 0x82;
	_FF01Value = len;
	gData[len++] = 0x00;
	gData[len++] = 0x00;
	startData = len;


	for(i = 0; i < 20; i++)
	{
		gData[len++] = 0x9F;
		gData[len++] = 0x37;
		gData[len++] = 0x01;
		gData[len++] = torn[i].mUN;
	}

	gData[_FF01Value] = (len - startData) / 256;
	gData[_FF01Value+1] = (len -startData) - (gData[_FF01Value] * 256);

	pmwSendRawDD(gData,len);


	aceOut("Training Session - END\n");


	return 0;
}