// DK02Control_Console.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include <windows.h>
#include "Service.h"
#include "mxdk02.h"

#define DRIVER_FUNC_INSTALL     0x01
#define DRIVER_FUNC_REMOVE      0x02

#define DRIVER_NAME       "mxdk02"

BOOLEAN
ManageDriver(
    __in LPCTSTR  DriverName,
    __in LPCTSTR  ServiceName,
    __in USHORT   Function
    );

BOOLEAN
SetupDriverName(
    __inout_bcount_full(BufferLength) PCHAR DriverLocation,
    __in ULONG BufferLength
    );


#define DK02_DRIVER_NAME	"mxdk02.sys"
#define DK02_SERVICE_NAME	"mxdk02"
#define DK02_DISPLAY_NAME	"mxdk02 Service"

int _tmain(int argc, _TCHAR* argv[])
{
	char		dir_path[MAX_PATH];
	char		file_path[MAX_PATH];
	int			fd;
	int			slot_num;
	int			val;
	int			reg_val;
	int			count = 0;
	
	//
	// TODO: 
	// 
	/*Get current directrory*/
	GetCurrentDirectory(sizeof(dir_path),dir_path);
	sprintf(file_path, "%s\\%s",dir_path,DK02_DRIVER_NAME);

	if (argc < 2) {
		printf("Usage: mx-dk02-control slot_num [1/0]\n");
		return -1;
	}

	slot_num = atoi(argv[1]);
	if (strlen(argv[2]) > 1)  {
		printf("Incorrect val=%s\n", argv[2]);
		return -1;
	}
	val = atoi(argv[2]);

	if ((slot_num > 4) || (slot_num < 1) || (val > 1) || (val < 0)) {
		printf("Incorrect parameter\n");
		printf("Usage: mx-dk02-control slot_num [1/0]\n");
		return -1;
	}
	fd = mxdk02_open();
	if (fd == 0 )  {
		printf("Can't open the device mxdk02");
		return -1;
	}

	/*set the slot status*/
	reg_val = val ^ (((slot_num -1) & 0x1) > 0 ? 0 : 1);
	
	Sleep(1000);

	if (mxdk02_set_slot(fd, slot_num, reg_val)) 
		printf("Incorrect IOCTL!\n");
	else  if (val)
		printf("Power on the USB interface in slot %d\n", slot_num);
	else 
		printf("Power off the USB interface in slot %d\n", slot_num);

	mxdk02_close(fd);


	return 0;
}

