Example #1
0
/*..........................................................................*/
void BSP_init(void) {
    printf("Dining Philosopher Problem example\n"
           "QP-nano %s\n"
           "Press 'p' to pause\n"
           "Press ESC to quit...\n",
           QP_getVersion());
}
Example #2
0
int main() {
    printf("History state pattern\nQP-nano version: %s\n"
           "Press 'o' to OPEN  the door\n"
           "Press 'c' to CLOSE the door\n"
           "Press 't' to start TOASTING\n"
           "Press 'b' to start BAKING\n"
           "Press 'f' to turn the oven OFF\n"
           "Press ESC to quit...\n",
           QP_getVersion());

    ToasterOven_ctor(&l_test);        /* instantiate the ToasterOven object */
    QHsm_init((QHsm *)&l_test);           /* trigger the initial transition */

    for (;;) {
        uint8_t c;

        printf("\n");
        c = (uint8_t)_getch();       /* read one character from the console */
        printf("%c: ", c);

        switch (c) {
            case 'o':  Q_SIG(&l_test) = OPEN_SIG;      break;
            case 'c':  Q_SIG(&l_test) = CLOSE_SIG;     break;
            case 't':  Q_SIG(&l_test) = TOAST_SIG;     break;
            case 'b':  Q_SIG(&l_test) = BAKE_SIG;      break;
            case 'f':  Q_SIG(&l_test) = OFF_SIG;       break;
            case 0x1B: Q_SIG(&l_test) = TERMINATE_SIG; break;
        }
                               /* dispatch the event into the state machine */
        QHsm_dispatch((QHsm *)&l_test);
    }
    return 0;
}
Example #3
0
void main(void) {
    printf("Ultimate Hook pattern\nQP-nano version: %s\n"
           "Press 'a'..'c' to inject signals A..C\n"
           "Press 'd' or ESC to inject signal D and quit\n",
           QP_getVersion());

    UltimateHook_ctor(&l_test);      /* instantiate the UltimateHook object */
    QHsm_init((QHsm *)&l_test);           /* trigger the initial transition */

    for (;;) {
        uint8_t c;

        printf("\n");
        c = (uint8_t)getch();        /* read one character from the console */
        printf("%c: ", c);

        switch (c) {
            case 'a':  Q_SIG(&l_test) = A_SIG;  break;
            case 'b':  Q_SIG(&l_test) = B_SIG;  break;
            case 'c':  Q_SIG(&l_test) = C_SIG;  break;
            case 'd':
            case 0x1B: Q_SIG(&l_test) = D_SIG;  break;         /* terminate */
        }
                               /* dispatch the event into the state machine */
        QHsm_dispatch((QHsm *)&l_test);
    }
}
Example #4
0
/*..........................................................................*/
void BSP_init(int argc, char *argv[]) {
    uint8_t n;

    if (argc > 1) {
        l_delay = atol(argv[1]);    /* set the delay counter for busy delay */
    }
    Video_clearScreen(VIDEO_BGND_BLACK);
    Video_clearRect( 0,  0, 80,  7, VIDEO_BGND_LIGHT_GRAY);
    Video_clearRect( 0, 11, 80, 12, VIDEO_BGND_LIGHT_GRAY);
    Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE);
    Video_clearRect(41, 12, 80, 23, VIDEO_BGND_RED);
    Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY);

    n = VIDEO_FGND_BLUE;
    Video_printStrAt(10, 0, n, "  __");
    Video_printStrAt(10, 1, n, " /  |      _   _ -|-     _ _");
    Video_printStrAt(10, 2, n, " \\__| | |  _\\ | \\ | | | | \\ \\");
    Video_printStrAt(10, 3, n, "    | \\_/ |_| | | | \\_| | | |");
    Video_printStrAt(10, 4, n, "    |");
    n = VIDEO_FGND_RED;
    Video_printStrAt(43, 0, n, "    _       __ ");
    Video_printStrAt(43, 1, n, "|  /_\\     |  \\  TM");
    Video_printStrAt(43, 2, n, "|  \\_   _  |__/ _");
    Video_printStrAt(43, 3, n, "|       _\\ |   |_");
    Video_printStrAt(43, 4, n, "|___   |_| |    _|");
    Video_printStrAt(10, 5, VIDEO_FGND_BLUE,
                     "_____________________________________________________");
    Video_printStrAt(10, 6, VIDEO_FGND_RED,
                     "i n n o v a t i n g   e m b e d d e d   s y s t e m s");
    Video_printStrAt(18,  7, VIDEO_FGND_WHITE,
                     "Dining Philosophers Problem (DPP)");
    Video_printStrAt(18,  8, VIDEO_FGND_WHITE, "QP-nano (QK) ");
    Video_printStrAt(32,  8, VIDEO_FGND_YELLOW, QP_getVersion());
    Video_printStrAt(41, 10, VIDEO_FGND_WHITE, "Delay Counter");
    Video_printNumAt(54, 10, VIDEO_FGND_YELLOW, l_delay);

    Video_printStrAt( 1, 11, VIDEO_FGND_BLUE,
                     "Active Object   State     Preemptions");

    Video_printStrAt(42, 11, VIDEO_FGND_RED,
                     "ISR      Calls    Data    Preemptions");
    for (n = 0; n < N_PHILO; ++n) {
        Video_printStrAt( 1, 12 + n, VIDEO_FGND_WHITE, "Philosopher");
        Video_printNumAt(12, 12 + n, VIDEO_FGND_WHITE, n);
    }
    Video_printStrAt( 1, 12 + N_PHILO, VIDEO_FGND_WHITE,  "Table");
    Video_printStrAt(17, 12 + N_PHILO, VIDEO_FGND_YELLOW, "serving");
    Video_printStrAt( 1, 12 + N_PHILO + 1, VIDEO_FGND_WHITE,  "KbdMgr");
    Video_printStrAt(17, 12 + N_PHILO + 1, VIDEO_FGND_YELLOW, "active");
    Video_printStrAt( 1, 12 + N_PHILO + 3, VIDEO_FGND_WHITE,  "Locked Sched");

    Video_printStrAt(42, 12 + 0, VIDEO_FGND_WHITE,  "kbdISR");
    Video_printStrAt(42, 12 + 1, VIDEO_FGND_WHITE,  "tmrISR");

    Video_printStrAt(10, 23, VIDEO_FGND_BLUE,
         "* Copyright (c) Quantum Leaps, LLC * www.quantum-leaps.com *");
    Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED,
         "<< Press Esc to quit >>");
}
Example #5
0
/*..........................................................................*/
void BSP_init(void) {
    printf("Dining Philosopher Problem example"
           "\nQP-nano %s\n"
           "Press 'p' to pause\n"
           "Press ESC to quit...\n",
           QP_getVersion());
    BSP_randomSeed(1234U);
}
Example #6
0
/*..........................................................................*/
void BSP_init(int argc, char *argv[]) {
    if (argc > 1) {
        l_delay = atol(argv[1]);    /* set the delay counter for busy delay */
    }
    printf("Dining Philosopher Problem example"
           "\nQP-nano %s\n"
           "Press ESC to quit...\n",
           QP_getVersion());
}
Example #7
0
/*..........................................................................*/
void BSP_init(void) {
    printf("Pedestrian LIght CONtrolled crossing example"
           "\nQP-nano %s\n"
           "Press 'p' to generate PED_WAITING\n"
           "Press 'f' to generate OFF\n"
           "Press 'o' to generate ON\n"
           "Press ESC to quit...\n",
           QP_getVersion());
}
Example #8
0
/*..........................................................................*/
QState UI_top_handler(UI_top *me) {
    switch (Q_SIG(me)) {
        case Q_ENTRY_SIG: {
            uint8_t c;
            Video_clearScreen(VIDEO_BGND_BLACK);
            Video_clearRect( 0,  0, 80,  7, VIDEO_BGND_LIGHT_GRAY);
            Video_clearRect( 0, 10, 80, 11, VIDEO_BGND_LIGHT_GRAY);
            Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY);

            c = VIDEO_FGND_BLUE;
            Video_printStrAt(10, 0, c, "  __");
            Video_printStrAt(10, 1, c, " /  |      _   _ -|-     _ _");
            Video_printStrAt(10, 2, c, " \\__| | |  _\\ | \\ | | | | \\ \\");
            Video_printStrAt(10, 3, c, "    | \\_/ |_| | | | \\_| | | |");
            Video_printStrAt(10, 4, c, "    |");
            c = VIDEO_FGND_RED;
            Video_printStrAt(43, 0, c, "    _       __ ");
            Video_printStrAt(43, 1, c, "|  /_\\     |  \\  TM");
            Video_printStrAt(43, 2, c, "|  \\_   _  |__/ _");
            Video_printStrAt(43, 3, c, "|       _\\ |   |_");
            Video_printStrAt(43, 4, c, "|___   |_| |    _|");
            Video_printStrAt(10, 5, VIDEO_FGND_BLUE,
                "_____________________________________________________");
            Video_printStrAt(10, 6, VIDEO_FGND_RED,
                "i n n o v a t i n g   e m b e d d e d   s y s t e m s");
            Video_printStrAt(2,  8, VIDEO_FGND_WHITE,
                "State-Local Storage Example");
            Video_printStrAt(36,  8, VIDEO_FGND_WHITE, "QP-nano");
            Video_printStrAt(45,  8, VIDEO_FGND_YELLOW, QP_getVersion());

            Video_printStrAt(10, 23, VIDEO_FGND_BLUE,
              "* Copyright (c) Quantum Leaps, LLC * www.quantum-leaps.com *");
            Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED,
                "<< Press Esc to quit >>");

            return Q_HANDLED();
        }
        case Q_EXIT_SIG: {
            Video_clearScreen(VIDEO_BGND_BLACK);     /* clear the screen... */
            return Q_HANDLED();
        }
        case QUIT_SIG: {
            return Q_TRAN(&UI_top_final);
        }
    }
    return Q_SUPER(&QHsm_top);
}
Example #9
0
/*..........................................................................*/
int main (void) {
    AlarmClock_ctor();

    printf("Orthogonal Component state pattern\nQP-nano version: %s\n"
           "Press 'o' to turn the Alarm ON\n"
           "Press 'f' to turn the Alarm OFF\n"
           "Press '0'..'9' to set the Alarm time\n"
           "Press 'A' to set the Clock in 12-hour mode\n"
           "Press 'B' to set the Clock in 24-hour mode\n"
           "Press ESC to quit...\n",
           QP_getVersion());


    BSP_init();                                     /* initialize the board */

    return QF_run();                         /* transfer control to QF-nano */
}
Example #10
0
/*..........................................................................*/
int main(int argc, char *argv[]) {
    QHsmTst_ctor();                       /* instantiate the QHsmTst object */

    if (argc > 1) {                                  /* file name provided? */
        l_outFile = fopen(argv[1], "w");
    }

    if (l_outFile == (FILE *)0) {                   /* interactive version? */
        l_outFile = stdout;            /* use the stdout as the output file */

        printf("QHsmTst example, built on %s at %s,\n"
               "QP-nano: %s.\nPress ESC to quit...\n",
               __DATE__, __TIME__, QP_getVersion());

        QHsm_init(the_hsm);                   /* the top-most initial tran. */

        for (;;) {                                            /* event loop */
            int c;

            printf("\n>");
            c = _getche();    /* get a character from the console with echo */
            printf(": ");

            if ('a' <= c && c <= 'i') {                        /* in range? */
                Q_SIG(the_hsm) = (QSignal)(c - 'a' + A_SIG);
            }
            else if ('A' <= c && c <= 'I') {                   /* in range? */
                Q_SIG(the_hsm) = (QSignal)(c - 'A' + A_SIG);
            }
            else if (c == '\33') {                          /* the ESC key? */
                Q_SIG(the_hsm) = TERMINATE_SIG;
            }
            else {
                Q_SIG(the_hsm) = IGNORE_SIG;
            }

            QHsm_dispatch(the_hsm);                   /* dispatch the event */
        }
    }
    else {                                                 /* batch version */
        printf("QHsmTst example, built on %s at %s, QP-nano %s\n"
               "output saved to %s\n",
               __DATE__, __TIME__, QP_getVersion(),
               argv[1]);

        fprintf(l_outFile, "QHsmTst example, QP-nano %s\n",
                QP_getVersion());

        QHsm_init(the_hsm);                 /* take the initial transitioin */

                                       /* testing of dynamic transitions... */
        dispatch(A_SIG);
        dispatch(B_SIG);
        dispatch(D_SIG);
        dispatch(E_SIG);
        dispatch(I_SIG);
        dispatch(F_SIG);
        dispatch(I_SIG);
        dispatch(I_SIG);
        dispatch(F_SIG);
        dispatch(A_SIG);
        dispatch(B_SIG);
        dispatch(D_SIG);
        dispatch(D_SIG);
        dispatch(E_SIG);
        dispatch(G_SIG);
        dispatch(H_SIG);
        dispatch(H_SIG);
        dispatch(C_SIG);
        dispatch(G_SIG);
        dispatch(C_SIG);
        dispatch(C_SIG);

        fclose(l_outFile);
    }

    return 0;
}
Example #11
0
/*..........................................................................*/
void BSP_init(void) {
    uint8_t n;

    Video_clearScreen(VIDEO_BGND_BLACK);
    Video_clearRect( 0,  0, 80,  7, VIDEO_BGND_LIGHT_GRAY);
    Video_clearRect( 0, 11, 41, 12, VIDEO_BGND_LIGHT_GRAY);
    Video_clearRect( 0,  7, 41, 11, VIDEO_BGND_RED);
    Video_clearRect( 0, 12, 41, 23, VIDEO_BGND_BLUE);
    Video_clearRect( 0, 23, 80, 24, VIDEO_BGND_LIGHT_GRAY);

    n = VIDEO_FGND_BLUE;
    Video_printStrAt(10, 0, n, "  __");
    Video_printStrAt(10, 1, n, " /  |      _   _ -|-     _ _");
    Video_printStrAt(10, 2, n, " \\__| | |  _\\ | \\ | | | | \\ \\");
    Video_printStrAt(10, 3, n, "    | \\_/ |_| | | | \\_| | | |");
    Video_printStrAt(10, 4, n, "    |");
    n = VIDEO_FGND_RED;
    Video_printStrAt(43, 0, n, "    _       __ ");
    Video_printStrAt(43, 1, n, "|  /_\\     |  \\  TM");
    Video_printStrAt(43, 2, n, "|  \\_   _  |__/ _");
    Video_printStrAt(43, 3, n, "|       _\\ |   |_");
    Video_printStrAt(43, 4, n, "|___   |_| |    _|");
    Video_printStrAt(10, 5, VIDEO_FGND_BLUE,
                     "_____________________________________________________");
    Video_printStrAt(10, 6, VIDEO_FGND_RED,
                     "i n n o v a t i n g   e m b e d d e d   s y s t e m s");
    Video_printStrAt(10,  8, VIDEO_FGND_WHITE,
                    "PELICAN Crossing Example");
    Video_printStrAt(10,  9, VIDEO_FGND_WHITE, "QP-nano");
    Video_printStrAt(20,  9, VIDEO_FGND_YELLOW, QP_getVersion());

    Video_printStrAt(4, 11, VIDEO_FGND_BLUE,
                     "Active Object   State");
    Video_printStrAt(4, 13, VIDEO_FGND_WHITE, "PELICAN");
    Video_printStrAt(4, 14, VIDEO_FGND_WHITE, "Pedestrian");

    Video_printStrAt(4, 17, VIDEO_FGND_WHITE, "Tick #");

    n = VIDEO_FGND_WHITE | VIDEO_BGND_BLACK;
    Video_printStrAt(43,  7, n, "      �������Ŀ");
    Video_printStrAt(43,  8, n, "      �       �");
    Video_printStrAt(43,  9, n, "      �       �");
    Video_printStrAt(43, 10, n, "      ���������");
    Video_printStrAt(43, 11, n, "��������������������������������");
    Video_printStrAt(43, 12, n, "  ^   ���������");
    Video_printStrAt(43, 13, n, "  |   ���������");
    Video_printStrAt(43, 14, n, " PEDS ���������  <- CARS ->");
    Video_printStrAt(43, 15, n, "  |   ���������");
    Video_printStrAt(43, 16, n, "  v   ���������");
    Video_printStrAt(43, 17, n, "��������������������������������");
    Video_printStrAt(43, 18, n, "                �������������Ŀ");
    Video_printStrAt(43, 19, n, "                � �Ŀ �Ŀ �Ŀ �");
    Video_printStrAt(43, 20, n, "                � � � � � � � �");
    Video_printStrAt(43, 21, n, "                � ��� ��� ��� �");
    Video_printStrAt(43, 22, n, "                ���������������");

    Video_printStrAt(4, 23, VIDEO_FGND_BLUE,
         "* Copyright (c) Quantum Leaps, LLC * www.quantum-leaps.com *");
    Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED,
         "<< Press Esc to quit >>");
}
Example #12
0
/*..........................................................................*/
int main(int argc, char *argv[]) {

    int j;
    QHsmTst_ctor();                                  /* instantiate the HSM */

    if (argc > 1) {                                  /* file name provided? */
        l_outFile = fopen(argv[1], "w");
    }

    if (l_outFile == (FILE *)0) {                   /* interactive version? */
        l_outFile = stdout;            /* use the stdout as the output file */

        printf("QHsmTst example, built on %s at %s,\n"
               "QP-nano: %s.\nPress ESC to quit...\n",
               __DATE__, __TIME__, QP_getVersion());

        QHsm_init((QHsm *)&HSM_QHsmTst);    /* take the initial transitioin */

        for (;;) {                                            /* event loop */
            int c;

            printf("\n>");
            c = getchar();
            printf(": ");
            /*
            if ('a' <= c && c <= 'i') {                        // in range?
                Q_SIG((QHsm *)&HSM_QHsmTst) = (QSignal)(c - 'a' + A_SIG);
            }
	else if ('A' <= c && c <= 'I') {                   // in range?
                Q_SIG((QHsm *)&HSM_QHsmTst) = (QSignal)(c - 'A' + A_SIG);
            }
            else if (c == '\33') {                          // the ESC key?
                Q_SIG((QHsm *)&HSM_QHsmTst) = TERMINATE_SIG;
            }
            else {
                Q_SIG((QHsm *)&HSM_QHsmTst) = IGNORE_SIG;
            }
            */

            //QHsm_dispatch((QHsm *)&HSM_QHsmTst);      /* dispatch the event */
        }
    }
    else {                                                 /* batch version */
        printf("QHsmTst example, built on %s at %s, QP-nano %s\n"
               "output saved to %s\n",
               __DATE__, __TIME__, QP_getVersion(),
               argv[1]);

        fprintf(l_outFile, "QHsmTst example, QP-nano %s\n",
        		QP_getVersion());

        QHsm_init((QHsm *)&HSM_QHsmTst);    /* take the initial transitioin */
	
        extern storeWait waiting [5];

	//init
	int iterations;
        int timerCheckPoint = 0;
        direct = NA;
        maxFloor = 4;
	for ( ; timePassed < 3000000; ){
        	timerCheckPoint = timePassed;
		//Controller loop
        	switch (direct){
        	case UP: {
        		if (ordersExistInDir(UP)){
        			dispatch(GO_UP);
        			dispatch(FLOOR_REACHED);
        		}
        		else {
        			direct = NA;
        		}
        		break;
        	}
        	case DOWN: {
        		if (ordersExistInDir(DOWN)){
        			dispatch(GO_DOWN);
        			dispatch(FLOOR_REACHED);
        		}
        		else {
        			direct = NA;
        		}
        		break;
        	}
        	case NA: {
        		if (ordersExistInDir(UP)){
        			dispatch(GO_UP);
        			dispatch(FLOOR_REACHED);
        		}
        		else if (ordersExistInDir(DOWN)){
        			dispatch(GO_DOWN);
        			dispatch(FLOOR_REACHED);
        		}
        		break;
        	}
        	}

		//To make the time go if nothing has been done in the elevator
        	if (timerCheckPoint == timePassed){
        		tick5();
        	}
        	
		//printStatus(waiting);
        	//printf("iteration no: %d",iterations);
		assert(currentFloor <= maxFloor && currentFloor >= 0);
        }
        printStatistics(waiting);
        fclose(l_outFile);
    }

    return 0;
}