📄 qhsmtst.c
字号:
/****************************************************************************** Product: QHsmTst Example* Last Updated for Version: 3.4.00* Date of the Last Update: Sep 04, 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 "qhsmtst.h"#include "qassert.h"/*..........................................................................*/void QHsmTst_ctor(QHsmTst *me) { QHsm_ctor(&me->super, (QState)&QHsmTst_initial);}/*..........................................................................*/void QHsmTst_initial(QHsmTst *me, QEvent const *e) { (void)e; /* suppress "e not used" compiler warning */ QHsmTst_display(me, "top-INIT;"); me->foo = 0; /* initialize extended state variable */ Q_INIT(&QHsmTst_s2);}/*..........................................................................*/QSTATE QHsmTst_s(QHsmTst *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QHsmTst_display(me, "s-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "s-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "s-INIT;"); Q_INIT(&QHsmTst_s11); return (QSTATE)0; } case E_SIG: { QHsmTst_display(me, "s-E;"); Q_TRAN_DYN(&QHsmTst_s11); return (QSTATE)0; } case I_SIG: { /* internal transition with a guard */ if (me->foo) { QHsmTst_display(me, "s-I;"); me->foo = 0; return (QSTATE)0; } break; } case TERMINATE_SIG: { QHsmTst_exit(me); return (QSTATE)0; } } return (QSTATE)&QHsm_top;}/*..........................................................................*/QSTATE QHsmTst_s1(QHsmTst *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QHsmTst_display(me, "s1-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "s1-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "s1-INIT;"); Q_INIT(&QHsmTst_s11); return (QSTATE)0; } case A_SIG: { QHsmTst_display(me, "s1-A;"); Q_TRAN_DYN(&QHsmTst_s1); return (QSTATE)0; } case B_SIG: { QHsmTst_display(me, "s1-B;"); Q_TRAN_DYN(&QHsmTst_s11); return (QSTATE)0; } case C_SIG: { QHsmTst_display(me, "s1-C;"); Q_TRAN_DYN(&QHsmTst_s2); return (QSTATE)0; } case D_SIG: { /* transition with a gurad */ if (!me->foo) { QHsmTst_display(me, "s1-D;"); me->foo = 1; Q_TRAN_DYN(&QHsmTst_s); return (QSTATE)0; /* event handled */ } break; } case F_SIG: { QHsmTst_display(me, "s1-F;"); Q_TRAN_DYN(&QHsmTst_s211); return (QSTATE)0; } case I_SIG: { /* internal transition */ QHsmTst_display(me, "s1-I;"); return (QSTATE)0; } } return (QSTATE)&QHsmTst_s;}/*..........................................................................*/QSTATE QHsmTst_s11(QHsmTst *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QHsmTst_display(me, "s11-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "s11-EXIT;"); return (QSTATE)0; } case D_SIG: { /* transition with a gurad */ if (me->foo) { QHsmTst_display(me, "s11-D;"); me->foo = 0; Q_TRAN_DYN(&QHsmTst_s1); return (QSTATE)0; /* event handled */ } break; } case G_SIG: { QHsmTst_display(me, "s11-G;"); Q_TRAN_DYN(&QHsmTst_s211); return (QSTATE)0; } case H_SIG: { QHsmTst_display(me, "s11-H;"); Q_TRAN_DYN(&QHsmTst_s); return (QSTATE)0; } } return (QSTATE)&QHsmTst_s1;}/*..........................................................................*/QSTATE QHsmTst_s2(QHsmTst *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QHsmTst_display(me, "s2-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "s2-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "s2-INIT;"); Q_INIT(&QHsmTst_s211); return (QSTATE)0; } case C_SIG: { QHsmTst_display(me, "s2-C;"); Q_TRAN_DYN(&QHsmTst_s1); return (QSTATE)0; } case F_SIG: { QHsmTst_display(me, "s2-F;"); Q_TRAN_DYN(&QHsmTst_s11); return (QSTATE)0; } case I_SIG: { /* internal transition with a guard */ if (!me->foo) { QHsmTst_display(me, "s2-I;"); me->foo = (uint8_t)1; return (QSTATE)0; } break; } } return (QSTATE)&QHsmTst_s;}/*..........................................................................*/QSTATE QHsmTst_s21(QHsmTst *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QHsmTst_display(me, "s21-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "s21-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "s21-INIT;"); Q_INIT(&QHsmTst_s211); return (QSTATE)0; } case A_SIG: { QHsmTst_display(me, "s21-A;"); Q_TRAN_DYN(&QHsmTst_s21); return (QSTATE)0; } case B_SIG: { QHsmTst_display(me, "s21-B;"); Q_TRAN_DYN(&QHsmTst_s211); return (QSTATE)0; } case G_SIG: { QHsmTst_display(me, "s21-G;"); Q_TRAN_DYN(&QHsmTst_s1); return (QSTATE)0; } } return (QSTATE)&QHsmTst_s2;}/*..........................................................................*/QSTATE QHsmTst_s211(QHsmTst *me, QEvent const *e) { switch (e->sig) { case Q_ENTRY_SIG: { QHsmTst_display(me, "s211-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "s211-EXIT;"); return (QSTATE)0; } case D_SIG: { QHsmTst_display(me, "s211-D;"); Q_TRAN_DYN(&QHsmTst_s21); return (QSTATE)0; } case H_SIG: { QHsmTst_display(me, "s211-H;"); Q_TRAN_DYN(&QHsmTst_s); return (QSTATE)0; } } return (QSTATE)&QHsmTst_s21;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -