Ejemplo n.º 1
0
/*..........................................................................*/
int comp_main(int argc, char *argv[]) {
    printf("Orthogonal Component pattern\nQEP version: %s\nQF  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",
           QEP_getVersion(), QF_getVersion());

   

    QF_init();    /* initialize the framework and the underlying RT kernel */

    

                                               /* initialize event pools... */

    QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));

                             /* instantiate and start the active objects... */
    AlarmClock_ctor(&l_alarmClock);
    QActive_start((QActive *)&l_alarmClock, 1,
                  l_alarmClockQSto, Q_DIM(l_alarmClockQSto),
                  (void *)0, 0, (QEvent *)0);

    QF_run();                                     /* run the QF application */

    return 0;
}
int main() {
    printf("History state pattern\nQEP 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",
           QEP_getVersion());

      /* instantiate the ToastOven HSM and trigger the initial transition */
    ToastOven_ctor(&l_test);
    QHsm_init((QHsm *)&l_test, (QEvt *)0);

    for (;;) {
        QEvt e;
        uint8_t c;

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

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

    UltimateHook_ctor(&l_test);      /* instantiate the UltimateHook object */

                /* trigger the initial transition before dispatching events */
    QHsm_init((QHsm *)&l_test, (QEvt *)0);

    for (;;) {
        QEvt e;
        uint8_t c;

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

        switch (c) {
            case 'a':  e.sig = A_SIG;  break;
            case 'b':  e.sig = B_SIG;  break;
            case 'c':  e.sig = C_SIG;  break;
            case 'd':
            case 0x1B: e.sig = D_SIG;  break;                  /* terminate */
        }
                               /* dispatch the event into the state machine */
        QHsm_dispatch((QHsm *)&l_test, &e);
    }
}
/*..........................................................................*/
QState UI_top_handler(UI_top *me, QEvt const *e) {
    switch (e->sig) {
        case Q_ENTRY_SIG: {
            uint8_t c;
            static char const * const help_unknown[] = {
                "Unknown Screen Help:        ",
                "                            ",
                "                            ",
                "                            ",
                "                            "
            };
            me->help_text = help_unknown;
            me->help_len  = Q_DIM(help_unknown);

            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, "QEP/C");
            Video_printStrAt(45,  8, VIDEO_FGND_YELLOW, QEP_getVersion());
            Video_printStrAt(55,  8, VIDEO_FGND_WHITE, "QF/C");
            Video_printStrAt(64,  8, VIDEO_FGND_YELLOW, QF_getVersion());

            Video_printStrAt(10, 23, VIDEO_FGND_BLUE,
              "* Copyright (c) Quantum Leaps, LLC * www.state-machine.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);
}
Ejemplo n.º 5
0
/*..........................................................................*/
void BSP_init(void) {

    printf("Dining Philosopher Problem example"
           "\nQEP %s\nQF  %s\n"
           "Press 'p' to pause/un-pause\n"
           "Press ESC to quit...\n",
           QEP_getVersion(),
           QF_getVersion());

    BSP_randomSeed(1234U);
    Q_ALLEGE(QS_INIT((void *)0));
    QS_OBJ_DICTIONARY(&l_clock_tick);   /* must be called *after* QF_init() */
    QS_USR_DICTIONARY(PHILO_STAT);
}
Ejemplo n.º 6
0
/*..........................................................................*/
void BSP_init(int argc, char *argv[]) {
    char const *com = "COM1";

    if (argc > 1) {
        l_delay = atol(argv[1]);    /* set the delay counter for busy delay */
    }
    if (argc > 2) {
        com = argv[2];
        com = com;         /* avoid compiler warning about unused parameter */
    }
    if (!QS_INIT(com)) {                                   /* initialize QS */
        Q_ERROR();
    }

    QS_OBJ_DICTIONARY(&l_tmr);
    QS_OBJ_DICTIONARY(&l_kbd);

    printf("Dining Philosopher Problem example"
           "\nQEP %s\nQF  %s\n"
           "Press ESC to quit...\n",
           QEP_getVersion(),
           QF_getVersion());
}
Ejemplo n.º 7
0
/*..........................................................................*/
int main(int argc, char *argv[]) {
    printf("Reminder state pattern\nQEP version: %s\nQF  version: %s\n"
           "Press 'e' to echo the current value...\n"
           "Press ESC to quit...\n",
           QEP_getVersion(), QF_getVersion());

    Cruncher_ctor(&l_cruncher);

    BSP_init(argc, argv);                             /* initialize the BSP */

    QF_init();     /* initialize the framework and the underlying RT kernel */

    /* publish-subscribe not used, no call to QF_psInit() */

    QF_poolInit(l_smlPoolSto, sizeof(l_smlPoolSto), sizeof(l_smlPoolSto[0]));

                             /* instantiate and start the active objects... */
    QACTIVE_START((QActive *)&l_cruncher, 1,
                  l_cruncherQSto, Q_DIM(l_cruncherQSto),
                  (void *)0, 1024, (QEvt *)0);

    return QF_run();                              /* run the QF application */
}
Ejemplo n.º 8
0
/*..........................................................................*/
int main() {
    Calc_ctor();            /* explicitly instantiate the calculator object */

    printf("Calculator example, QEP version: %s\n"
           "Press '0' .. '9'     to enter a digit\n"
           "Press '.'            to enter the decimal point\n"
           "Press '+'            to add\n"
           "Press '-'            to subtract or negate a number\n"
           "Press '*'            to multiply\n"
           "Press '/'            to divide\n"
           "Press '%%'            to perform percentage calculation\n"
           "Press '=' or <Enter> to get the result\n"
           "Press 'c' or 'C'     to Cancel\n"
           "Press 'e' or 'E'     to Cancel Entry\n"
           "Press <Esc>          to quit.\n\n",
           QEP_getVersion());

    QMSM_INIT(the_calc, (QEvt *)0);           /* trigger initial transition */

    for (;;) {                                                /* event loop */
        CalcEvt e;                                      /* Calculator event */

        BSP_display();                                  /* show the display */

        printf(": ");
        fflush(stdout);
        e.key_code = (uint8_t)_getche();            /* get a char with echo */
        printf(" ");

        switch (e.key_code) {
            case 'c':                         /* intentionally fall through */
            case 'C': {
                ((QEvt *)&e)->sig = C_SIG;
                break;
            }
            case 'e':                         /* intentionally fall through */
            case 'E': {
                ((QEvt *)&e)->sig = CE_SIG;
                break;
            }
            case '0': {
                ((QEvt *)&e)->sig = DIGIT_0_SIG;
                break;
            }
            case '1':                         /* intentionally fall through */
            case '2':                         /* intentionally fall through */
            case '3':                         /* intentionally fall through */
            case '4':                         /* intentionally fall through */
            case '5':                         /* intentionally fall through */
            case '6':                         /* intentionally fall through */
            case '7':                         /* intentionally fall through */
            case '8':                         /* intentionally fall through */
            case '9': {
                ((QEvt *)&e)->sig = DIGIT_1_9_SIG;
                break;
            }
            case '.': {
                ((QEvt *)&e)->sig = POINT_SIG;
                break;
            }
            case '+':                         /* intentionally fall through */
            case '-':                         /* intentionally fall through */
            case '*':                         /* intentionally fall through */
            case '/': {
                ((QEvt *)&e)->sig = OPER_SIG;
                break;
            }
            case '=':                         /* intentionally fall through */
            case '\r': {                                       /* Enter key */
                ((QEvt *)&e)->sig = EQUALS_SIG;
                break;
            }
            case '%': {                                      /* Percent key */
                ((QEvt *)&e)->sig = PERCENT_SIG;
                break;
            }
            case '\33': {                                        /* ESC key */
                ((QEvt *)&e)->sig = OFF_SIG;
                break;
            }
            default: {
                ((QEvt *)&e)->sig = 0;                   /* invalid event */
                break;
            }
        }

        if (((QEvt *)&e)->sig != 0) {           /* valid event generated? */
            QMSM_DISPATCH(the_calc, (QEvt *)&e);        /* dispatch event */
        }
    }
    return 0;
}
Ejemplo n.º 9
0
int main(int argc, char* argv[])
{
    char cmdBuf[SOCK_BUFF_SIZE];

    printf("Quantum Test\nQEP %s\nQF  %s, QF/Linux port %s\n",
           QEP_getVersion(),
           QF_getVersion(), QF_getPortVersion());

    QF_init();
	QF_psInit(subscrSto, Q_DIM(subscrSto));
	QF_poolInit(poolArray, sizeof(poolArray), sizeof(GenEvt));
	
    applicationStart(QSIZE);

    for (;;)
    {
      // Get the incoming string command from the dmsTerminal or the GUI
      receiveCmd(cmdBuf);


	  // Attempt to parse the command string for IMPL or ACTIVE calls
	   char tmpBuf[USER_ENTRY_SIZE];
	   char smName[USER_ENTRY_SIZE];
	   char attrName[USER_ENTRY_SIZE];
	   char valStr[USER_ENTRY_SIZE];
	   // scan for IMPL['SM'].set("attr", True/False), allowing blanks
	   // IMPL['trans'].set('guard', False)
	   int cnt = sscanf(strcpy(tmpBuf, cmdBuf),
			   "IMPL[%*['\"]%[^'\"]%*['\"]].set(%*['\"]%[^'\"]%*['\"],%[^)])",
			   smName, attrName, valStr);
	   if (cnt > 0) {  // found an IMPL attribute setter!
		   setGuardAttribute(smName, attrName, valStr);
		   continue;
	   }

      char *word;
      word = strtok(cmdBuf, " ");

      // We assume the first word contains the signal that is to be published,
      // and the remaining words are data to be used to populate the event.
      GenEvt *event;
      int signal = strtoul(word, NULL, 10);
      if (signal == DURING)
      {
        QF_tick();
        QF_publish( Q_NEW(QEvent, DURING) );
      }
      else
      {
        event = Q_NEW(GenEvt, signal);
        // Loop through the remaining words and populate the event
        int i = 0;
        do
        {
           word = strtok('\0', " ");
           if (word)
           {
             Q_ASSERT(i<EVENT_SIZE);
             event->data[i] = strtoul(word, NULL, 16);
           }
           i = i + 1;
        } while (word);
        QF_publish((QEvent *)event);
      }
      QF_run();
    }
}
Ejemplo n.º 10
0
/*..........................................................................*/
void BSP_init(int argc, char *argv[]) {
    char const *com = "COM1";
    uint8_t n;

    if (argc > 1) {
        l_delay = atol(argv[1]); /* set the delay counter for busy delay */
    }
    if (argc > 2) {
        com = argv[2];
        (void)com; /* avoid compiler warning if Q_SPY not defined */
    }
    if (!QS_INIT(com)) { /* initialize QS */
        Q_ERROR();
    }

    QS_OBJ_DICTIONARY(&l_tickHook);
    QS_OBJ_DICTIONARY(&l_kbdTask);

    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 Example");
    Video_printStrAt(18,  8, VIDEO_FGND_WHITE, "QEP/C");
    Video_printStrAt(28,  8, VIDEO_FGND_YELLOW, QEP_getVersion());
    Video_printStrAt(18,  9, VIDEO_FGND_WHITE, "QF/C");
    Video_printStrAt(28,  9, VIDEO_FGND_YELLOW, QF_getVersion());
    Video_printStrAt(18, 10, VIDEO_FGND_WHITE, "uC/OS-II");

    /* uC/OS-II version is returned as an integer value multiplied by 100 */
    Video_printNumAt(29, 10, VIDEO_FGND_YELLOW, OSVersion()%100);
    Video_printStrAt(28, 10, VIDEO_FGND_YELLOW, "2.");

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

    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 + 1);
    }
    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,  "ucosTask");
    Video_printStrAt(17, 12 + N_PHILO + 1, VIDEO_FGND_YELLOW, "active");

    Video_printStrAt(4, 23, VIDEO_FGND_BLUE,
         "* Copyright (c) Quantum Leaps, LLC * www.state-machine.com *");
    Video_printStrAt(28, 24, VIDEO_FGND_LIGHT_RED,
         "<< Press Esc to quit >>");
}
Ejemplo n.º 11
0
    printf("Quantum DPP\nQEP %s\nQF  %s, QF port %s\n"
           "Press ESC to quit...\n",
           QEP_getVersion(),
           QF_getVersion(), QF_getPortVersion());
/*..........................................................................*/
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"
               "QEP: %s.\nPress ESC to quit...\n",
               __DATE__, __TIME__, QEP_getVersion());

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

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

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

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

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

        fprintf(l_outFile, "QHsmTst example, QEP %s\n",
                QEP_getVersion());

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

                                       /* 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;
}