// i8172W_FR_2054DIO.c : Defines the entry point for the console application.
//
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <unistd.h>
#include "msw.h"
#include "i8172W.h"

int main(int argc, char **argv)
{
	int id, slot=2, RetValue=0;
	int diData,group,i,channel,mode,status,port,doData,bitVal;

	RetValue = Open_Slot(slot);
	if (RetValue >0) {
		printf("Open Slot %d failed!\n",slot);
		return FAILURE;
	}else {
		id = i8172W_Init(slot);
		if (id==0)
			printf("\nThere is a I-8172W located at Slot %d.\n",slot);
		else {
			printf("There is no I-8172W located at LinPAC.\n");
			return FAILURE;
		}
	}

	printf("Please input the port number of i-8172W (Range: 0 or 1): ");
	scanf("%d",&port);

	printf("Please input the group index(Dip switch) of FR-2057 (Range: 0~7): ");
	scanf("%d",&group);

	printf("\n<< Operation mode >>\n");
	printf("  0. Write single channel output \n");
	printf("  1. Write multi channel output \n");
	printf("Please input operation mode: ");
	scanf("%d",&mode);
   
	switch(mode)
	{
		case 0:
			printf("\nPlease input channel number (Range: 0~16): ");
			scanf("%d",&bitVal);

			printf("\nPlease input status (0:OFF, 1:ON ): ");
			scanf("%d",&status);
			i8172W_WriteDOBit(slot,port,group,bitVal,status);
		break;

		case 1:
			printf("\nEnter DO Data (0 ~ 0xffff): ");
			scanf("%X",&doData);
			i8172W_WriteDOGroup(slot, port, group, doData & 0xffff);
		break;
	}

	Close_Slot(slot);
	return 0;
}
