/*
	BL17PLC.C
	
	This program simply calls in all the functions visible to the
	end user and makes sure that everything compiles.
*/

#use eziobl17.lib
#use ezioplc2.lib
#use eziocmmn.lib
#use eziopbdv.lib
#use vdriver.lib

void testXP81() {
	auto unsigned int i;
	auto unsigned int j;

	for (i = 0; i < 8; ++i) {
		if (plcXP81In(i*32) == -1) {
		} else {
			printf("XP8100 board # %d is found\n  ",i);
			for (j = 0; j < 32; ++j) {
				printf(plcXP81In(i*32+j)?"1":"0");
			}
			printf("\n");
		}
	}
}

void testXP82() {
	auto unsigned int i;
	auto unsigned int j;
	auto unsigned long t;

	for (i = 0; i < 8; ++i) {
		if (plcXP82In(i*16) == -1) {
		} else {
			printf("XP8200 board # %d is found\n",i);
			for (j = 0; j < 16; ++j) {
				printf(plcXP82In(i*16+j)?"1":"0");
			}
			printf("\n");
		}
	}
}

void testXP83_4() {
	auto unsigned int i;
	auto unsigned int j;
	auto unsigned long t;

	for (i = 0; i < 8; ++i) {
		if (plcXP83Out(i*8,0) == -1) {
		} else {
			printf("XP8300/XP8400 board # %d is found\n",i);
			for (j = 0; j < 6; ++j) {
				plcXP83Out(i*8+j,1);
				t = MS_TIMER;
				while (MS_TIMER - t < 200);
				plcXP83Out(i*8+j,0);
			}
		}
	}
}

void testXP85() {
	auto unsigned int i;
	auto unsigned int j;

	for (i = 0; i < 4; ++i) {
		if (plcXP85Init(i) == -1) {
		} else {
			printf("XP8500 board # %d is found\n",i);
			for (j = 0; j < 11; ++j) {
				printf("  channel %d reads 0x%04x\n",j,plcXP85In(i*16+j));
			}
		}
	}
}

void testXP86() {
	auto unsigned int i,j;
	
	for (i = 0; i < 8; ++i) {
		if (plcXP86Init(i) == -1) {
		} else {
			printf("XP8600 board # %d is found\n",i);
			for (j = 0; j < 1024; ++j) {
				plcXP86Out(0,j);
				plcXP86Out(1,1023-j);
			}
			for (j = 0; j < 1024; ++j) {
				plcXP86Out(0,1023-j);
				plcXP86Out(1,j);
			}
		}
	}
}

main() {
	VdInit();
	plcBusReset();
	eioPlcRstWait();

	testXP81();
	testXP82();
	testXP83_4();
	testXP85();
	testXP86();
	plcXP81In;			//	IO32
	plcXP81Out;
	plcXP82In;			//	UIO
	plcXP82Out;
	plcXP83Out;			//	Relay6
	plcXP84Out;			//	Relay8
	plcXP85Init;		//	ADC4
	plcXP85In;
	plcXP85InC;
	plcXP86Init;		//	DAC2
	plcXP86Out;
	
}