Calc is the model of the Calculator described in Chapter 4 of PSiCC2 Calculator state machine BSP_clear(); (void)e; /* unused parameter */ BSP_message("on-ENTRY;"); BSP_message("on-EXIT;"); BSP_message("on-INIT;"); BSP_clear(); BSP_message("error-ENTRY;"); BSP_message("error-EXIT;"); BSP_message("ready-ENTRY;"); BSP_message("ready-EXIT;"); BSP_message("ready-INIT;"); BSP_clear(); BSP_clear(); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_clear(); BSP_insert((int)'0'); BSP_insert((int)'.'); me->operand1 = BSP_get_value(); me->operator = Q_EVT_CAST(CalcEvt)->key_code; BSP_message("result-ENTRY;"); BSP_message("result-EXIT;"); BSP_message("begin-ENTRY;"); BSP_message("begin-EXIT;"); Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS else BSP_message("operand1-ENTRY;"); BSP_message("operand1-EXIT;"); BSP_clear(); me->operand1 = BSP_get_value(); me->operator = Q_EVT_CAST(CalcEvt)->key_code; BSP_message("zero1-ENTRY;"); BSP_message("zero1-EXIT;"); ; BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_insert((int)'0'); BSP_insert((int)'.'); BSP_message("int1-ENTRY;"); BSP_message("int1-EXIT;"); BSP_insert((int)'.'); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_message("frac1-ENTRY;"); BSP_message("frac1-EXIT;"); ; BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_message("negated1-ENTRY;"); BSP_negate(); BSP_message("negated1-EXIT;"); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); else Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS ; BSP_message("opEntered-ENTRY;"); BSP_message("opEntered-EXIT;"); BSP_clear(); BSP_clear(); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_clear(); BSP_insert((int)'0'); BSP_insert((int)'.'); Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS else BSP_message("operand2-ENTRY;"); BSP_message("operand2-EXIT;"); BSP_clear(); else BSP_eval(me->operand1, me->operator, BSP_get_value()) else BSP_eval(me->operand1, me->operator, BSP_get_value()) BSP_message("zero2-ENTRY;"); BSP_message("zero2-EXIT;"); ; BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_insert((int)'0'); BSP_insert((int)'.'); BSP_message("int2-ENTRY;"); BSP_message("int2-EXIT;"); BSP_insert((int)'.'); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_message("frac2-ENTRY;"); BSP_message("frac2-EXIT;"); ; BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_message("negated2-ENTRY;"); BSP_negate(); BSP_message("negated2-EXIT;"); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); BSP_insert(Q_EVT_CAST(CalcEvt)->key_code); else Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS ; BSP_message("final-ENTRY;"); BSP_exit(); constructor Calc *me = &l_calc; QMsm_ctor(&me->super, Q_STATE_CAST(&Calc_initial)); #ifndef calc1_h #define calc1_h enum CalcSignals { C_SIG = Q_USER_SIG, CE_SIG, DIGIT_0_SIG, DIGIT_1_9_SIG, POINT_SIG, OPER_SIG, EQUALS_SIG, OFF_SIG }; $declare(Events::CalcEvt) $declare(SMs::Calc_ctor) extern QMsm * const the_calc; /* "opaque" pointer to calculator MSM */ #endif /* calc1_h */ #include "qpc.h" /* QP/C */ #include "bsp.h" /* board support package */ #include "calc1.h" /* application */ $declare(SMs::Calc) static Calc l_calc; /* the only instance of the Calc class */ /* global-scope definitions ---------------------------------------*/ QMsm * const the_calc = &l_calc.super; /* "opaque" pointer to MSM */ $define(SMs::Calc_ctor) $define(SMs::Calc)