 1Content-type: application/x-Unknown; charset=UTF8package nmc.sidekick;

import com.ajile.io.BufferedInputStream;
import com.ajile.jem.rawJEM;
import nmc.sidekick.RtcTime;

public class TestRunner {

    public static int a1;
    public static int a2;
    public static int a3;
    public static int a4;

    public static int loopsRun = 0; // Really just so compiler doesn't
                                    // optimize TestRunnerBkptFn out of
                                    // existence.

    public static int param0 = 0;
    public static int param1 = 1;
    public static int param2 = 2;
    public static int param3 = 3;
    public static int param4 = 4;


    /**
     * Starts the application.
     * @param args an array of command-line arguments
     */
    public static void main(java.lang.String[] args) {

        DebugMessage.setOutDevice(DebugMessage.SYSTEM_OUT);

        DebugMessage.println("Hello from the TestRunner...");

        int done = 0;

        // Remove this when Instantiator can be used --
        // it's done there, and it should be done only there.
        {
            Rtc.initialize(); // set up gpio pin(s)
            Rtc temp = Rtc.getInstance();
            temp.initSpiForRtcTest();
        }


//          DebugMessage.println("set up the DPA boards...");
// 	 Instantiator.InitSpiBus();
//          Instantiator.FindDpaBoards();
//          Instantiator.InitDpaChannelsOnly();
//          System.out.println("...done setting up the DPA boards/channels");


        while (done == 0) {
            TestRunnerBkptFn();
            done = runTest(param0, param1, param2, param3);
            DebugMessage.println("Completed test, done=" + done);
        }


    }

    public static void TestRunnerBkptFn() {
        loopsRun++;
    }

    public static int runTest( int testNum, int arg1, int arg2, int arg3) {
        Ramtest r = null;
        RtcTime tm=null;
        Rtc rtc = Rtc.getInstance();
        int retval = 0;

        switch(testNum) {
        case 1:
            // ramtest
            r = new Ramtest();
            break;
        case 2:
            // flashtest
            DebugMessage.println("flashtest not implemented yet");
            break;
        case 3:
            // enetloopback
            DebugMessage.println("enetloopback not implemented yet");
            break;
        case 4:
            // uartinternalloopback <port number>
            DebugMessage.println("doing loopback for com" + arg1);
            UartLoopbackTest.doInternalLoopback(arg1);
            break;
        case 5:
            // uartexternalloopback <port number>
            DebugMessage.println("doing loopback for com" + arg1);
            UartLoopbackTest.doExternalLoopback(arg1);
            break;
        case 6:
            // adc
            break;
        case 7:
            // setdate
            DebugMessage.println("Setting Date: "+arg1+"/"+arg2+"/"+arg3);

            tm = rtc.getTime();
            DebugMessage.println("Date read: "+tm);
            rtc.setTime(arg1,arg2,arg3,tm.hour,tm.minute,tm.second);
            DebugMessage.println("Reading date...");
            tm = rtc.getTime();
            DebugMessage.println("Date set : "+tm);
            break;
        case 8:
            // settime
            DebugMessage.println("Setting time: "+arg1+":"+arg2+":"+arg3);

            tm = rtc.getTime();
            DebugMessage.println("Time read: "+tm);
            rtc.setTime(tm.year,tm.month,tm.day,arg1,arg2,arg3);
            DebugMessage.println("Reading time...");
            tm = rtc.getTime();
            DebugMessage.println("Time set : "+tm);

            break;
        case 9:
            // getdate
           //NOTE fallthrough
        case 10:
            // gettime
            DebugMessage.println("Getting time/date...");

            tm = rtc.getTime();
            DebugMessage.println("Time/Date read: "+tm);
            break;
        case 11:
            // setwakeup
            break;
        case 12:
            // pressure
            break;
        case 13:
            // temperature
            break;
        case 14:
            // dpaspi
            System.out.println("dpaspi called, board=" + arg1
                               + "; value=0x" + Integer.toHexString(arg2));
            retval = DpaBoard.writeReadSpi(1<<arg1, arg2);
            System.out.println("dpaspi returns 0x" + Integer.toHexString(retval));
            break;
        case 15:
            // dpaspiadc
            break;
        case 16:
            // quit
            DebugMessage.println("Quit requested, TestRunner exiting...");
            return 1; // done
        default:
            DebugMessage.println("unrecognized operation number: " + testNum);
            break;
        }

        return 0; // meaning not done yet
    }

    public static void fn1() {
        DebugMessage.println("fn1 is running");
        Ramtest ramtest = new Ramtest();
    }

    public static void fn2() {
        DebugMessage.println("fn2 is running");
    }

}
