////////////////////////////////////////////////////////////////////////////////
// Copyright (c) Datacard Corporation.  All Rights Reserved.
////////////////////////////////////////////////////////////////////////////////
package com.datacard.xpsprinter.sdk.examples;

import common_java.XPS_Java_SDK;

public class Smartcard_Singlewire_Omnikey_Main {
    
    public static void main(String[] args) {
        int i = 0;
        String arg;
        
    	String  printerName     = "";
    	String  cardType        = "";
        boolean nameGiven       = false;
        boolean print           = false;
        boolean pollCompletion  = false;

        new XPS_Java_SDK(); // construct and extract interop dll

        // parse the command line arguments
        while (i < args.length) {
            arg = args[i++];

            if (arg.equalsIgnoreCase("-n")) {
                if (i < args.length) {
                    printerName = args[i++];
                    nameGiven = true;
                } else {
                    System.err.println("-n requires a printername");
                    break;
                }
            } else if (arg.equals("-p") && nameGiven) {
            	print = true;
            } else if (arg.equals("-c") && nameGiven) {
            	pollCompletion = true;
            } else if (arg.equalsIgnoreCase("-t")) {
                if (i < args.length) {
                	cardType = args[i++];
                } else {
                    System.err.println("-t requires a 'card type'.");
                    System.exit(-1);
                    break;
                }
            } else {
                usage();
                System.exit(0);
            }
        }

        if (i < 2) {
            usage();
            System.exit(0);
        }
        
        if (printerName.isEmpty() || cardType.isEmpty()) {
            usage();
            System.exit(0);
        }        

        Smartcard_Singlewire_Omnikey smartCard = new Smartcard_Singlewire_Omnikey(printerName);
        smartCard.DemoSmartCard(cardType, print, pollCompletion);

    }

    
    public static void usage() {
        System.out.println();
        System.out.println("demonstrates interactive mode parking in the ");
        System.out.println("smart card reader, performing single-wire smart card functions, and moving the ");
        System.out.println("card from the reader. It has options to print and poll for job completion. ");
        System.out.println("The omnikey reader supports multiple cards types, allowing you to select  ");
        System.out.println("the type of card used. For each card type, the omnikey reader performs a  ");
        System.out.println("series of functions, described below.        " );
        System.out.println();
        System.out.println(" java -jar Smartcard_Singlewire_Omnikey.jar -n <printername> -t <cardType> [-p] [-c]");
        System.out.println();
        System.out.println("options:");
        System.out.println("  -n <printername>. Required. Try -n \"XPS Card Printer\".");
        System.out.println("  -t <cardtype>. Required. Specify one of the following:");
        System.out.println("      -t Mifare. Reads the card ID and status, and reads and writes data to");
        System.out.println("         block 2.");
        System.out.println("      -t iClass. Reads the card ID and status, and reads and writes data to");
        System.out.println("         block 18.");
        System.out.println("      -t HIDProx. Reads the card ID (UID) and facility code (FAC).");
        System.out.println("  -p Print sample text on the card.");
        System.out.println("  -c Poll for job completion.");
        System.out.println();
    }
}
