mirror of
https://github.com/QuantumLeaps/qpc.git
synced 2025-02-04 07:13:16 +08:00
736 lines
25 KiB
XML
736 lines
25 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<model version="4.6.0" links="1">
|
|
<documentation>Improved model of the Calculator described in Chapter 4 of PSiCC2. Improvements include:
|
|
|
|
- placing the "negated1" state inside "operand1" superstate
|
|
- placing the "negated2" state inside "operand2" superstate
|
|
- adding handling of operator precedence '*','/' before '+','-'</documentation>
|
|
<!--${qpc}-->
|
|
<framework name="qpc"/>
|
|
<!--${Events}-->
|
|
<package name="Events" stereotype="0x01">
|
|
<!--${Events::CalcEvt}-->
|
|
<class name="CalcEvt" superclass="qpc::QEvt">
|
|
<!--${Events::CalcEvt::key_code}-->
|
|
<attribute name="key_code" type="uint8_t" visibility="0x00" properties="0x00"/>
|
|
</class>
|
|
</package>
|
|
<!--${SMs}-->
|
|
<package name="SMs" stereotype="0x02">
|
|
<!--${SMs::Calc}-->
|
|
<class name="Calc" superclass="qpc::QHsm">
|
|
<documentation>Calculator state machine</documentation>
|
|
<!--${SMs::Calc::inst}-->
|
|
<attribute name="inst" type="Calc" visibility="0x00" properties="0x01">
|
|
<documentation>The only inst of the Calc object (Singleton pattern).</documentation>
|
|
</attribute>
|
|
<!--${SMs::Calc::op1}-->
|
|
<attribute name="op1" type="double" visibility="0x02" properties="0x00"/>
|
|
<!--${SMs::Calc::op2}-->
|
|
<attribute name="op2" type="double" visibility="0x02" properties="0x00"/>
|
|
<!--${SMs::Calc::oper1}-->
|
|
<attribute name="oper1" type="uint8_t" visibility="0x02" properties="0x00"/>
|
|
<!--${SMs::Calc::oper2}-->
|
|
<attribute name="oper2" type="uint8_t" visibility="0x02" properties="0x00"/>
|
|
<!--${SMs::Calc::eval}-->
|
|
<operation name="eval" type="bool" visibility="0x02" properties="0x00">
|
|
<documentation>/* guard function to evaluate the current expression
|
|
* taking into account the precedence of operands.
|
|
* return: true if evaluation successfull
|
|
* false when error encountered
|
|
*/</documentation>
|
|
<!--${SMs::Calc::eval::op}-->
|
|
<parameter name="op" type="double"/>
|
|
<!--${SMs::Calc::eval::oper}-->
|
|
<parameter name="oper" type="uint8_t"/>
|
|
<code>double result;
|
|
if ((oper == KEY_NULL) || (oper == KEY_PLUS) || (oper == KEY_MINUS)) {
|
|
switch (me->oper2) {
|
|
case KEY_MULT: {
|
|
me->op2 *= op;
|
|
break;
|
|
}
|
|
case KEY_DIVIDE: {
|
|
if ((-1e-30 < op) && (op < 1e-30)) {
|
|
BSP_display_error(" Error 0 "); /* divide by zero */
|
|
return false;
|
|
}
|
|
me->op2 /= op;
|
|
break;
|
|
}
|
|
default: { /* no op2 yet */
|
|
me->op2 = op;
|
|
me->oper2 = oper;
|
|
break;
|
|
}
|
|
}
|
|
switch (me->oper1) {
|
|
case KEY_PLUS: {
|
|
me->op1 += me->op2;
|
|
break;
|
|
}
|
|
case KEY_MINUS: {
|
|
me->op1 -= me->op2;
|
|
break;
|
|
}
|
|
case KEY_MULT: {
|
|
me->op1 *= me->op2;
|
|
break;
|
|
}
|
|
case KEY_DIVIDE: {
|
|
if ((-1e-30 < me->op2) && (me->op2 < 1e-30)) {
|
|
BSP_display_error(" Error 0 "); /* divide by zero */
|
|
return false;
|
|
}
|
|
me->op1 /= me->op2;
|
|
break;
|
|
}
|
|
default: {
|
|
Q_ERROR();
|
|
break;
|
|
}
|
|
}
|
|
me->oper1 = oper;
|
|
me->oper2 = KEY_NULL;
|
|
result = me->op1;
|
|
}
|
|
else { /* (oper == KEY_MULT) || (oper == KEY_DIV) */
|
|
switch (me->oper2) {
|
|
case KEY_MULT: {
|
|
me->op2 *= op;
|
|
break;
|
|
}
|
|
case KEY_DIVIDE: {
|
|
if ((-1e-30 < op) && (op < 1e-30)) {
|
|
BSP_display_error(" Error 0 "); /* divide by zero */
|
|
return false;
|
|
}
|
|
me->op2 /= op;
|
|
break;
|
|
}
|
|
default: { /* oper2 not provided yet */
|
|
me->op2 = op;
|
|
break;
|
|
}
|
|
}
|
|
me->oper2 = oper;
|
|
result = me->op2;
|
|
}
|
|
|
|
if ((result < -99999999.0) || (99999999.0 < result)) {
|
|
BSP_display_error(" Error 1 "); /* out of range */
|
|
return false;
|
|
}
|
|
if ((-0.0000001 < result) && (result < 0.0000001)) {
|
|
result = 0.0;
|
|
}
|
|
BSP_display(result);
|
|
|
|
return true;</code>
|
|
</operation>
|
|
<!--${SMs::Calc::SM}-->
|
|
<statechart properties="0x01">
|
|
<!--${SMs::Calc::SM::initial}-->
|
|
<initial target="../1">
|
|
<action>(void)e; /* unused parameter */</action>
|
|
<initial_glyph conn="2,2,5,1,94,4,-2">
|
|
<action box="1,-2,13,4"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<!--${SMs::Calc::SM::on}-->
|
|
<state name="on">
|
|
<entry>BSP_message("on-ENTRY;");</entry>
|
|
<exit>BSP_message("on-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::initial}-->
|
|
<initial target="../4">
|
|
<action>BSP_message("on-INIT;");
|
|
BSP_clear();</action>
|
|
<initial_glyph conn="49,10,5,1,13,8,-2">
|
|
<action box="1,0,5,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<!--${SMs::Calc::SM::on::C}-->
|
|
<tran trig="C" target="..">
|
|
<tran_glyph conn="2,12,3,1,92">
|
|
<action box="0,-2,12,4"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::OFF}-->
|
|
<tran trig="OFF" target="../../2">
|
|
<tran_glyph conn="2,14,3,1,94,104,-77">
|
|
<action box="0,0,5,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::error}-->
|
|
<state name="error">
|
|
<documentation>/* Error state after evaluation of an expression.
|
|
This state can be exited only throgh the inherited C (Clear) event.
|
|
*/</documentation>
|
|
<entry>BSP_message("error-ENTRY;");</entry>
|
|
<exit>BSP_message("error-EXIT;");</exit>
|
|
<state_glyph node="12,68,10,8">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::ready}-->
|
|
<state name="ready">
|
|
<entry>BSP_message("ready-ENTRY;");
|
|
me->oper2 = KEY_NULL;</entry>
|
|
<exit>BSP_message("ready-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::ready::initial}-->
|
|
<initial target="../6">
|
|
<action>BSP_message("ready-INIT;");</action>
|
|
<initial_glyph conn="20,20,5,0,20,2">
|
|
<action box="0,-2,6,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<!--${SMs::Calc::SM::on::ready::DIGIT_0}-->
|
|
<tran trig="DIGIT_0" target="../../5/3">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="20,34,2,0,11">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::ready::DIGIT_1_9}-->
|
|
<tran trig="DIGIT_1_9" target="../../5/4">
|
|
<action>BSP_clear();
|
|
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="34,34,2,0,11">
|
|
<action box="1,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::ready::POINT}-->
|
|
<tran trig="POINT" target="../../5/5">
|
|
<action>BSP_clear();
|
|
BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="54,34,2,0,11">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::ready::OPER}-->
|
|
<tran trig="OPER" target="../../6">
|
|
<action>me->op1 = BSP_get_value();
|
|
me->oper1 = Q_EVT_CAST(CalcEvt)->key_code;</action>
|
|
<tran_glyph conn="60,24,1,1,32,48,-32">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::ready::result}-->
|
|
<state name="result">
|
|
<entry>BSP_message("result-ENTRY;");</entry>
|
|
<exit>BSP_message("result-EXIT;");</exit>
|
|
<state_glyph node="16,22,10,10">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::ready::begin}-->
|
|
<state name="begin">
|
|
<entry>BSP_message("begin-ENTRY;");</entry>
|
|
<exit>BSP_message("begin-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::ready::begin::OPER}-->
|
|
<tran trig="OPER">
|
|
<!--${SMs::Calc::SM::on::ready::begin::OPER::[e->key=='-']}-->
|
|
<choice target="../../../../5/6">
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<choice_glyph conn="42,30,5,0,34,15">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<!--${SMs::Calc::SM::on::ready::begin::OPER::[else]}-->
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="42,30,4,-1,-4,4">
|
|
<action box="1,-3,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="32,30,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="32,22,16,10">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="10,16,50,18">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand1}-->
|
|
<state name="operand1">
|
|
<entry>BSP_message("operand1-ENTRY;");</entry>
|
|
<exit>BSP_message("operand1-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand1::CE}-->
|
|
<tran trig="CE" target="../../4">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="84,38,0,1,-10,-24">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::OPER}-->
|
|
<tran trig="OPER" target="../../6">
|
|
<action>me->op1 = BSP_get_value();
|
|
me->oper1 = Q_EVT_CAST(CalcEvt)->key_code;</action>
|
|
<tran_glyph conn="62,64,2,1,6,-2">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::EQUALS}-->
|
|
<tran trig="EQUALS" target="../../4/5">
|
|
<tran_glyph conn="12,38,0,3,-12,4">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::zero1}-->
|
|
<state name="zero1">
|
|
<entry>BSP_message("zero1-ENTRY;");</entry>
|
|
<exit>BSP_message("zero1-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand1::zero1::DIGIT_0}-->
|
|
<tran trig="DIGIT_0">
|
|
<action>;</action>
|
|
<tran_glyph conn="14,56,3,-1,10">
|
|
<action box="0,-2,7,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::zero1::DIGIT_1_9}-->
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="14,53,3,3,16,-6,2">
|
|
<action box="0,-2,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::zero1::POINT}-->
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="16,58,2,2,2,40,-2">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="14,45,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand1::int1}-->
|
|
<state name="int1">
|
|
<entry>BSP_message("int1-ENTRY;");</entry>
|
|
<exit>BSP_message("int1-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand1::int1::POINT}-->
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="32,53,3,3,16,-6,2">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::int1::DIGIT_0, DIGIT_1_9}-->
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="32,56,3,-1,10">
|
|
<action box="0,-2,14,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="32,45,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand1::frac1}-->
|
|
<state name="frac1">
|
|
<entry>BSP_message("frac1-ENTRY;");</entry>
|
|
<exit>BSP_message("frac1-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand1::frac1::POINT}-->
|
|
<tran trig="POINT">
|
|
<action>;</action>
|
|
<tran_glyph conn="50,56,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::frac1::DIGIT_0, DIGIT_1_9}-->
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="50,53,3,-1,10">
|
|
<action box="0,-2,15,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="50,45,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand1::negated1}-->
|
|
<state name="negated1">
|
|
<entry>BSP_message("negated1-ENTRY;");
|
|
BSP_negate();</entry>
|
|
<exit>BSP_message("negated1-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand1::negated1::DIGIT_0}-->
|
|
<tran trig="DIGIT_0" target="../../3">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="68,57,2,2,4,-44,-3">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::negated1::DIGIT_1_9}-->
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="75,57,2,2,5,-35,-4">
|
|
<action box="0,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::negated1::POINT}-->
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="83,57,2,2,6,-25,-5">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand1::negated1::OPER}-->
|
|
<tran trig="OPER">
|
|
<!--${SMs::Calc::SM::on::operand1::negated1::OPER::[else]}-->
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="76,53,4,-1,-4,8">
|
|
<action box="1,-4,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<!--${SMs::Calc::SM::on::operand1::negated1::OPER::[e->key=='-']}-->
|
|
<choice>
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<action>;</action>
|
|
<choice_glyph conn="76,53,5,-1,8">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="66,53,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="66,45,22,12">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="10,38,80,26">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::opEntered}-->
|
|
<state name="opEntered">
|
|
<entry>BSP_message("opEntered-ENTRY;");</entry>
|
|
<exit>BSP_message("opEntered-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::opEntered::DIGIT_0}-->
|
|
<tran trig="DIGIT_0" target="../../7/3">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="30,82,2,0,8,-6,3">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::opEntered::DIGIT_1_9}-->
|
|
<tran trig="DIGIT_1_9" target="../../7/4">
|
|
<action>BSP_clear();
|
|
BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="40,82,2,0,11">
|
|
<action box="1,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::opEntered::POINT}-->
|
|
<tran trig="POINT" target="../../7/5">
|
|
<action>BSP_clear();
|
|
BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="54,82,2,0,11">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::opEntered::OPER}-->
|
|
<tran trig="OPER">
|
|
<!--${SMs::Calc::SM::on::opEntered::OPER::[e->key=='-']}-->
|
|
<choice target="../../../7/6">
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<choice_glyph conn="36,78,5,0,40,15">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<!--${SMs::Calc::SM::on::opEntered::OPER::[else]}-->
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="36,78,4,-1,-4,4">
|
|
<action box="1,-3,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="28,78,3,-1,8">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="28,68,32,14">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand2}-->
|
|
<state name="operand2">
|
|
<entry>BSP_message("operand2-ENTRY;");</entry>
|
|
<exit>BSP_message("operand2-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand2::CE}-->
|
|
<tran trig="CE" target="../../6">
|
|
<action>BSP_clear();</action>
|
|
<tran_glyph conn="82,86,0,1,-10,-22">
|
|
<action box="0,-4,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::EQUALS}-->
|
|
<tran trig="EQUALS">
|
|
<!--${SMs::Calc::SM::on::operand2::EQUALS::[else]}-->
|
|
<choice target="../../../3">
|
|
<guard brief="else"/>
|
|
<choice_glyph conn="4,70,5,3,8">
|
|
<action box="1,0,7,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<!--${SMs::Calc::SM::on::operand2::EQUALS::[Calc_eval(me,BSP_get_value(),KE~}-->
|
|
<choice target="../../../4/5">
|
|
<guard>Calc_eval(me, BSP_get_value(), KEY_NULL)</guard>
|
|
<choice_glyph conn="4,70,4,3,-46,12">
|
|
<action box="-3,-5,14,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="10,108,3,-1,-6,-38">
|
|
<action box="-5,-2,10,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::OPER}-->
|
|
<tran trig="OPER">
|
|
<!--${SMs::Calc::SM::on::operand2::OPER::[Calc_eval(me,BSP_get_value(),Q_~}-->
|
|
<choice target="../../../6">
|
|
<guard>Calc_eval(me, BSP_get_value(), Q_EVT_CAST(CalcEvt)->key_code)</guard>
|
|
<choice_glyph conn="6,80,5,3,18,-6,4">
|
|
<action box="1,0,18,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<!--${SMs::Calc::SM::on::operand2::OPER::[else]}-->
|
|
<choice target="../../../3">
|
|
<guard brief="else"/>
|
|
<choice_glyph conn="6,80,4,3,-6,6">
|
|
<action box="0,-6,10,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="10,104,3,-1,-4,-24">
|
|
<action box="-4,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::zero2}-->
|
|
<state name="zero2">
|
|
<entry>BSP_message("zero2-ENTRY;");</entry>
|
|
<exit>BSP_message("zero2-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand2::zero2::DIGIT_0}-->
|
|
<tran trig="DIGIT_0">
|
|
<action>;</action>
|
|
<tran_glyph conn="14,104,3,-1,10">
|
|
<action box="0,-2,7,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::zero2::DIGIT_1_9}-->
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="14,101,3,3,16,-6,2">
|
|
<action box="0,-2,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::zero2::POINT}-->
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'0');
|
|
BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="16,106,2,2,2,40,-2">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="14,93,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand2::int2}-->
|
|
<state name="int2">
|
|
<entry>BSP_message("int2-ENTRY;");</entry>
|
|
<exit>BSP_message("int2-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand2::int2::POINT}-->
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert((int)'.');</action>
|
|
<tran_glyph conn="32,101,3,3,16,-6,2">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::int2::DIGIT_0, DIGIT_1_9}-->
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="32,104,3,-1,10">
|
|
<action box="0,-2,14,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="32,93,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand2::frac2}-->
|
|
<state name="frac2">
|
|
<entry>BSP_message("frac2-ENTRY;");</entry>
|
|
<exit>BSP_message("frac2-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand2::frac2::POINT}-->
|
|
<tran trig="POINT">
|
|
<action>;</action>
|
|
<tran_glyph conn="50,104,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::frac2::DIGIT_0, DIGIT_1_9}-->
|
|
<tran trig="DIGIT_0, DIGIT_1_9">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="50,101,3,-1,10">
|
|
<action box="0,-2,15,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="50,93,14,13">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::on::operand2::negated2}-->
|
|
<state name="negated2">
|
|
<entry>BSP_message("negated2-ENTRY;");
|
|
BSP_negate();</entry>
|
|
<exit>BSP_message("negated2-EXIT;");</exit>
|
|
<!--${SMs::Calc::SM::on::operand2::negated2::DIGIT_0}-->
|
|
<tran trig="DIGIT_0" target="../../3">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="68,105,2,2,4,-44,-3">
|
|
<action box="0,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::negated2::DIGIT_1_9}-->
|
|
<tran trig="DIGIT_1_9" target="../../4">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="75,105,2,2,5,-37,-4">
|
|
<action box="0,0,9,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::negated2::POINT}-->
|
|
<tran trig="POINT" target="../../5">
|
|
<action>BSP_insert(Q_EVT_CAST(CalcEvt)->key_code);</action>
|
|
<tran_glyph conn="83,105,2,2,6,-25,-5">
|
|
<action box="1,0,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<!--${SMs::Calc::SM::on::operand2::negated2::OPER}-->
|
|
<tran trig="OPER">
|
|
<!--${SMs::Calc::SM::on::operand2::negated2::OPER::[else]}-->
|
|
<choice>
|
|
<guard>else</guard>
|
|
<choice_glyph conn="76,102,4,-1,-4,8">
|
|
<action box="1,-4,6,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<!--${SMs::Calc::SM::on::operand2::negated2::OPER::[e->key=='-']}-->
|
|
<choice>
|
|
<guard brief="e->key == '-'">Q_EVT_CAST(CalcEvt)->key_code == KEY_MINUS</guard>
|
|
<action>;</action>
|
|
<choice_glyph conn="76,102,5,-1,8">
|
|
<action box="1,0,11,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="66,102,3,-1,10">
|
|
<action box="0,-2,6,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="66,93,22,12">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="10,86,80,26">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="2,4,92,110">
|
|
<entry box="1,2,5,2"/>
|
|
<exit box="1,4,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<!--${SMs::Calc::SM::final}-->
|
|
<state name="final">
|
|
<entry>BSP_message("final-ENTRY;");
|
|
BSP_exit();</entry>
|
|
<state_glyph node="2,116,17,6">
|
|
<entry box="1,2,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_diagram size="98,124"/>
|
|
</statechart>
|
|
</class>
|
|
<!--${SMs::the_calc}-->
|
|
<attribute name="the_calc" type="QHsm * const" visibility="0x00" properties="0x00">
|
|
<documentation>Global opaque pointer to the Calc inst</documentation>
|
|
<code>= &Calc_inst.super;</code>
|
|
</attribute>
|
|
<!--${SMs::Calc_ctor}-->
|
|
<operation name="Calc_ctor" type="void" visibility="0x00" properties="0x00">
|
|
<documentation>constructor</documentation>
|
|
<code>Calc *me = &Calc_inst;
|
|
QHsm_ctor(&me->super, Q_STATE_CAST(&Calc_initial));</code>
|
|
</operation>
|
|
</package>
|
|
<!--${.}-->
|
|
<directory name=".">
|
|
<!--${.::calc1.h}-->
|
|
<file name="calc1.h">
|
|
<text>#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 QHsm * const the_calc; /* "opaque" pointer to calculator HSM */
|
|
|
|
#endif /* CALC1_H */
|
|
</text>
|
|
</file>
|
|
<!--${.::calc1.c}-->
|
|
<file name="calc1.c">
|
|
<text>#include "qpc.h" /* QP/C */
|
|
#include "bsp.h" /* board support package */
|
|
#include "calc1.h" /* application */
|
|
|
|
Q_DEFINE_THIS_FILE
|
|
|
|
#define KEY_NULL '\0'
|
|
#define KEY_PLUS '+'
|
|
#define KEY_MINUS '-'
|
|
#define KEY_MULT '*'
|
|
#define KEY_DIVIDE '/'
|
|
|
|
$declare${SMs::Calc}
|
|
|
|
$define${SMs::the_calc}
|
|
$define${SMs::Calc_ctor}
|
|
$define${SMs::Calc}</text>
|
|
</file>
|
|
</directory>
|
|
</model>
|