📄 qhsmtst.c
字号:
/****************************************************************************** QHsmTst example* Last Updated for Version: 1.5.00* Date of the Last Update: Sep 17, 2006** Copyright (C) 2002-2006 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 allow the* licensees to retain the proprietary status of their code. The licensees* who use this software under one of Quantum Leaps commercial licenses do* not use this software under the GPL and therefore are not subject to any* of its terms.** Contact information:* Quantum Leaps Web site: http://www.quantum-leaps.com* Quantum Leaps licensing: http://www.quantum-leaps.com/licensing* Quantum Leaps products: http://www.quantum-leaps.com/products* e-mail: sales@quantum-leaps.com*****************************************************************************/#include "qpn_port.h"#include "qhsmtst.h"/* QHsmTst class -----------------------------------------------------------*/static QSTATE QHsmTst_initial(QHsmTst *me); /* initial state-handler */static QSTATE QHsmTst_d(QHsmTst *me); /* state-handler */static QSTATE QHsmTst_d1(QHsmTst *me); /* state-handler */static QSTATE QHsmTst_d11(QHsmTst *me); /* state-handler */static QSTATE QHsmTst_d2(QHsmTst *me); /* state-handler */static QSTATE QHsmTst_d21(QHsmTst *me); /* state-handler */static QSTATE QHsmTst_d211(QHsmTst *me); /* state-handler *//*..........................................................................*/void QHsmTst_ctor(QHsmTst *me) { QHsm_ctor(me, &QHsmTst_initial); /* instantiate the superclass */ me->foo__ = 0; /* initialize extended state variable */}/*..........................................................................*/QSTATE QHsmTst_initial(QHsmTst *me) { switch (Q_SIG(me)) { case Q_TOP_INIT_SIG: { QHsmTst_display(me, "top-INIT;"); Q_TRAN(&QHsmTst_d2); return (QSTATE)0; } } return (QSTATE)&QHsm_top;}/*..........................................................................*/QSTATE QHsmTst_d(QHsmTst *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QHsmTst_display(me, "d-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "d-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "d-INIT;"); Q_INIT(&QHsmTst_d11); return (QSTATE)0; } case E_SIG: { QHsmTst_display(me, "d-E;"); Q_TRAN(&QHsmTst_d11); return (QSTATE)0; } case I_SIG: { /* internal transition with a guard */ if (me->foo__) { QHsmTst_display(me, "d-I;"); me->foo__ = 0; return (QSTATE)0; } break; } case TERMINATE_SIG: { QHsmTst_exit(me); return (QSTATE)0; } } return (QSTATE)&QHsm_top;}/*..........................................................................*/QSTATE QHsmTst_d1(QHsmTst *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QHsmTst_display(me, "d1-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "d1-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "d1-INIT;"); Q_INIT(&QHsmTst_d11); return (QSTATE)0; } case A_SIG: { QHsmTst_display(me, "d1-A;"); Q_TRAN(&QHsmTst_d1); return (QSTATE)0; } case B_SIG: { QHsmTst_display(me, "d1-B;"); Q_TRAN(&QHsmTst_d11); return (QSTATE)0; } case C_SIG: { QHsmTst_display(me, "d1-C;"); Q_TRAN(&QHsmTst_d2); return (QSTATE)0; } case D_SIG: { /* transition with a gurad */ if (!me->foo__) { QHsmTst_display(me, "d1-D;"); me->foo__ = 1; Q_TRAN(&QHsmTst_d); return (QSTATE)0; /* event handled */ } break; } case F_SIG: { QHsmTst_display(me, "d1-F;"); Q_TRAN(&QHsmTst_d211); return (QSTATE)0; } case I_SIG: { /* internal transition */ QHsmTst_display(me, "d1-I;"); return (QSTATE)0; } } return (QSTATE)&QHsmTst_d;}/*..........................................................................*/QSTATE QHsmTst_d11(QHsmTst *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QHsmTst_display(me, "d11-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "d11-EXIT;"); return (QSTATE)0; } case D_SIG: { /* transition with a gurad */ if (me->foo__) { QHsmTst_display(me, "d11-D;"); me->foo__ = 0; Q_TRAN(&QHsmTst_d1); return (QSTATE)0; /* event handled */ } break; } case G_SIG: { QHsmTst_display(me, "d11-G;"); Q_TRAN(&QHsmTst_d211); return (QSTATE)0; } case H_SIG: { QHsmTst_display(me, "d11-H;"); Q_TRAN(&QHsmTst_d); return (QSTATE)0; } } return (QSTATE)&QHsmTst_d1;}/*..........................................................................*/QSTATE QHsmTst_d2(QHsmTst *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QHsmTst_display(me, "d2-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "d2-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "d2-INIT;"); Q_INIT(&QHsmTst_d211); return (QSTATE)0; } case C_SIG: { QHsmTst_display(me, "d2-C;"); Q_TRAN(&QHsmTst_d1); return (QSTATE)0; } case F_SIG: { QHsmTst_display(me, "d2-F;"); Q_TRAN(&QHsmTst_d11); return (QSTATE)0; } case I_SIG: { /* internal transition with a guard */ if (!me->foo__) { QHsmTst_display(me, "d2-I;"); me->foo__ = (uint8_t)1; return (QSTATE)0; } break; } } return (QSTATE)&QHsmTst_d;}/*..........................................................................*/QSTATE QHsmTst_d21(QHsmTst *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QHsmTst_display(me, "d21-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "d21-EXIT;"); return (QSTATE)0; } case Q_INIT_SIG: { QHsmTst_display(me, "d21-INIT;"); Q_INIT(&QHsmTst_d211); return (QSTATE)0; } case A_SIG: { QHsmTst_display(me, "d21-A;"); Q_TRAN(&QHsmTst_d21); return (QSTATE)0; } case B_SIG: { QHsmTst_display(me, "d21-B;"); Q_TRAN(&QHsmTst_d211); return (QSTATE)0; } case G_SIG: { QHsmTst_display(me, "d21-G;"); Q_TRAN(&QHsmTst_d1); return (QSTATE)0; } } return (QSTATE)&QHsmTst_d2;}/*..........................................................................*/QSTATE QHsmTst_d211(QHsmTst *me) { switch (Q_SIG(me)) { case Q_ENTRY_SIG: { QHsmTst_display(me, "d211-ENTRY;"); return (QSTATE)0; } case Q_EXIT_SIG: { QHsmTst_display(me, "d211-EXIT;"); return (QSTATE)0; } case D_SIG: { QHsmTst_display(me, "d211-D;"); Q_TRAN(&QHsmTst_d21); return (QSTATE)0; } case H_SIG: { QHsmTst_display(me, "d211-H;"); Q_TRAN(&QHsmTst_d); return (QSTATE)0; } } return (QSTATE)&QHsmTst_d21;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -