⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 main.c

📁 量子编程源代码 量子编程源代码
💻 C
字号:
/****************************************************************************** Product: QHsmTst Example* Last Updated for Version: 3.4.00* Date of the Last Update:  Sep 03, 2007**                    Q u a n t u m     L e a P s*                    ---------------------------*                    innovating embedded systems** Copyright (C) 2002-2007 Quantum Leaps, LLC. All rights reserved.** This software may be distributed and modified under the terms of the GNU* General Public License version 2 (GPL) as published by the Free Software* Foundation and appearing in the file GPL.TXT included in the packaging of* this file. Please note that GPL Section 2[b] requires that all works based* on this software must also be made publicly available under the terms of* the GPL ("Copyleft").** Alternatively, this software may be distributed and modified under the* terms of Quantum Leaps commercial licenses, which expressly supersede* the GPL and are specifically designed for licensees interested in* retaining the proprietary status of their code.** Contact information:* Quantum Leaps Web site:  http://www.quantum-leaps.com* e-mail:                  info@quantum-leaps.com*****************************************************************************/#include "qep_port.h"#include "qs_port.h"                        /* QS instrumentation interface */#include "qassert.h"#include "qhsmtst.h"#include <conio.h>#include <stdlib.h>#include <stdio.h>#include <time.h>Q_DEFINE_THIS_FILE/* local objects -----------------------------------------------------------*/static FILE *l_outFile = (FILE *)0;static void dispatch(QSignal sig);/* Q_SPY -------------------------------------------------------------------*/#ifdef Q_SPYenum QSQHsmTstRecords {    QS_QHSMTST_DISPLAY = QS_USER};static FILE *l_qsFile;                  /* file for collecting the QS trace */#define QS_BUF_SIZE  (256*2)/*..........................................................................*/uint8_t QS_init(void const *arg) {    static uint8_t qsBuf[QS_BUF_SIZE];            /* buffer for Quantum Spy */    QS_initBuf(qsBuf, sizeof(qsBuf));    l_qsFile = fopen((char const *)arg, "wb");              /* write binary */    return (uint8_t)(l_qsFile != (FILE *)0);      /* the status of the file */}/*..........................................................................*/void QS_exit(void) {    fclose(l_qsFile);                                         /* cleanup QS */}/*..........................................................................*/QSTimeCtr QS_getTime(void) {    return (QSTimeCtr)clock();}/*..........................................................................*/#define QS_DUMP() do { \    uint16_t nBytes = QS_BUF_SIZE; \    uint8_t const *block = QS_getBlock(&nBytes); \    if (block != (uint8_t *)0) { \        fwrite(block, 1, nBytes, l_qsFile); \    } \} while (0)/*..........................................................................*/void QS_flush() {    uint16_t nBytes = QS_BUF_SIZE;    uint8_t const *block;    while ((block = QS_getBlock(&nBytes)) != (uint8_t *)0) {        fwrite(block, 1, nBytes, l_qsFile);        nBytes = QS_BUF_SIZE;    }}#endif                                                             /* Q_SPY *//*--------------------------------------------------------------------------*/int main(int argc, char *argv[]) {    if (!QS_INIT("qs.bin")) {                          /* initialize the QS */        printf("Unable to open QSpy file\n");        return -1;    }    QS_FILTER_ON(QS_ALL_RECORDS);                /* setup the QS filters... */    QS_FILTER_OFF(QS_QHSMTST_DISPLAY);    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/C: %s.\nPress ESC to quit...\n",               __DATE__, __TIME__, QEP_getVersion());        qhsmtst_init();        /* instantiate and trigger the 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? */                c = c - 'a' + A_SIG;            }            else if ('A' <= c && c <= 'I') {                   /* in range? */                c = c - 'A' + A_SIG;            }            else if (c == '\33') {                          /* the ESC key? */                c = TERMINATE_SIG;        /* terminate the interactive test */            }            else {                c = IGNORE_SIG;            }            dispatch((QSignal)c);                     /* dispatch the event */        }    }    else {                                                 /* batch version */        printf("QHsmTst example, built on %s at %s, QEP/C %s\n"               "output saved to %s\n",               __DATE__, __TIME__, QEP_getVersion(),               argv[1]);        fprintf(l_outFile, "QHsmTst example, QEP/C %s\n",                QEP_getVersion());        qhsmtst_init();        /* instantiate and trigger the 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);    }    QS_EXIT();                                            /* cleanup the QS */    return 0;}/*..........................................................................*/void Q_assert_handler(char const Q_ROM * const Q_ROM_VAR file, int line) {    fprintf(stderr, "Assertion failed in %s, line %d", file, line);    exit(-1);}/*..........................................................................*/void BSP_display(char const *msg) {    fprintf(l_outFile, msg);    QS_BEGIN(QS_QHSMTST_DISPLAY, the_hsm);/* application-specific QS record */        QS_STR(msg);    QS_END();}/*..........................................................................*/void BSP_exit(void) {    printf("Bye, Bye!");    exit(0);}/*..........................................................................*/static void dispatch(QSignal sig) {    QEvent e;    e.sig = sig;    fprintf(l_outFile, "\n%c:", (sig <= I_SIG) ? 'A' + sig - A_SIG : '?');    QHsm_dispatch(the_hsm, &e);                       /* dispatch the event */    QS_DUMP();                                        /* dump the QS buffer */}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -