460 lines
15 KiB
Plaintext
Raw Normal View History

2016-09-01 11:58:57 -04:00
<?xml version="1.0" encoding="UTF-8"?>
2018-10-25 11:13:01 -04:00
<model version="4.3.1" links="0">
2018-05-07 16:05:00 -04:00
<documentation>Calc is the model of the Calculator described in Chapter 4 of PSiCC2. This version uses submachines and submachine states.</documentation>
2019-02-15 18:12:00 -05:00
<framework name="qpcpp" license="../../../QPCPP-EVAL.qlc"/>
2016-09-01 11:58:57 -04:00
<package name="Events" stereotype="0x01">
<class name="CalcEvt" superclass="qpcpp::QEvt">
<attribute name="key_code" type="uint8_t" visibility="0x00" properties="0x00"/>
</class>
</package>
<package name="SMs" stereotype="0x02">
<class name="Calc" superclass="qpcpp::QMsm">
<documentation>Calculator state machine</documentation>
<attribute name="m_op1" type="double" visibility="0x02" properties="0x00"/>
<attribute name="m_oper" type="uint8_t" visibility="0x02" properties="0x00"/>
<operation name="Calc" type="" visibility="0x00" properties="0x00">
<documentation>constructor</documentation>
<code> : QMsm(Q_STATE_CAST(&amp;Calc::initial))</code>
</operation>
2018-10-25 11:13:01 -04:00
<statechart properties="QS_FUN_DICT">
2016-09-01 11:58:57 -04:00
<initial target="../1">
<action>BSP_clear();
(void)e; // unused parameter</action>
<initial_glyph conn="2,2,5,1,92,4,-2">
<action box="1,-2,13,4"/>
</initial_glyph>
</initial>
<state name="on">
<entry>BSP_message(&quot;on-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;on-EXIT;&quot;);</exit>
<initial target="../3">
<action>BSP_message(&quot;on-INIT;&quot;);</action>
<initial_glyph conn="15,9,5,1,45,9,-2">
<action box="1,0,5,2"/>
</initial_glyph>
</initial>
<tran trig="C" target="..">
<action>BSP_clear();</action>
<tran_glyph conn="2,12,3,1,90">
<action box="0,-2,4,2"/>
</tran_glyph>
</tran>
<tran trig="OFF" target="../../2">
<tran_glyph conn="2,14,3,1,92,80,-75">
<action box="0,0,5,2"/>
</tran_glyph>
</tran>
<state name="ready">
<entry>BSP_message(&quot;ready-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;ready-EXIT;&quot;);</exit>
<initial target="../6">
<action>BSP_message(&quot;ready-INIT;&quot;);</action>
<initial_glyph conn="18,20,5,0,20,2">
<action box="0,-2,6,2"/>
</initial_glyph>
</initial>
<tran trig="DIGIT_0" target="../../4">
<action>BSP_clear();</action>
<tran_glyph conn="16,34,2,0,2,-4,4">
<action box="1,0,6,2"/>
</tran_glyph>
</tran>
<tran trig="DIGIT_1_9" target="../../4" cpref="../../../3/1">
<action>BSP_clear();
BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
2016-12-01 10:31:49 -05:00
<tran_glyph conn="32,34,2,0,5">
2016-09-01 11:58:57 -04:00
<action box="1,0,9,2"/>
</tran_glyph>
</tran>
2016-12-01 10:31:49 -05:00
<tran trig="POINT" target="../../4" cpref="../../../3/2">
2016-09-01 11:58:57 -04:00
<action>BSP_clear();
BSP_insert((int)'0');
BSP_insert((int)'.');</action>
2017-02-08 20:24:04 -05:00
<tran_glyph conn="49,34,2,0,5">
2016-09-01 11:58:57 -04:00
<action box="0,0,6,2"/>
</tran_glyph>
</tran>
<tran trig="OPER" target="../../5">
<action>me-&gt;m_op1 = BSP_get_value();
me-&gt;m_oper = Q_EVT_CAST(CalcEvt)-&gt;key_code;</action>
<tran_glyph conn="58,24,1,1,32,36,-32">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
<state name="result">
<entry>BSP_message(&quot;result-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;result-EXIT;&quot;);</exit>
<state_glyph node="14,22,10,10">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state name="begin">
<entry>BSP_message(&quot;begin-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;begin-EXIT;&quot;);</exit>
<tran trig="OPER">
<choice target="../../../../4" cpref="../../../../../3/3">
<guard brief="e-&gt;key == '-'">Q_EVT_CAST(CalcEvt)-&gt;key_code == KEY_MINUS</guard>
2016-12-01 10:31:49 -05:00
<choice_glyph conn="40,30,5,0,27,9">
2016-09-01 11:58:57 -04:00
<action box="1,0,11,2"/>
</choice_glyph>
</choice>
<choice>
<guard>else</guard>
<choice_glyph conn="40,30,4,-1,-4,4">
<action box="1,-3,6,2"/>
</choice_glyph>
</choice>
<tran_glyph conn="30,30,3,-1,10">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
<state_glyph node="30,22,16,10">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state_glyph node="8,16,50,18">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<smstate name="operand1" submachine="../../3">
<xpseg xpref="../../../3/4" target="../../3">
<action>BSP_message(&quot;operand1-XP:ce;&quot;);</action>
<xpseg_glyph conn="84,47,1,1,4,-21,-30">
<action box="1,0,10,2"/>
</xpseg_glyph>
</xpseg>
<tran trig="OPER" target="../../5">
<action>me-&gt;m_op1 = BSP_get_value();
me-&gt;m_oper = Q_EVT_CAST(CalcEvt)-&gt;key_code;</action>
<tran_glyph conn="42,52,2,0,4">
<action box="0,0,6,2"/>
</tran_glyph>
</tran>
<tran trig="EQUALS" target="../../3/5">
<tran_glyph conn="8,48,3,3,-2,-22,8">
<action box="-2,-3,9,2"/>
</tran_glyph>
</tran>
<smstate_glyph node="8,40,76,12"/>
</smstate>
<state name="opEntered">
<entry>BSP_message(&quot;opEntered-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;opEntered-EXIT;&quot;);</exit>
<tran trig="DIGIT_0" target="../../7" cpref="../../../3/0">
<action>BSP_clear();</action>
2016-12-01 10:31:49 -05:00
<tran_glyph conn="27,70,2,0,2,-11,3">
2016-09-01 11:58:57 -04:00
<action box="1,0,6,2"/>
</tran_glyph>
</tran>
<tran trig="DIGIT_1_9" target="../../7" cpref="../../../3/1">
<action>BSP_clear();
BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
2016-12-01 10:31:49 -05:00
<tran_glyph conn="34,70,2,0,4,-2,1">
2016-09-01 11:58:57 -04:00
<action box="1,0,9,2"/>
</tran_glyph>
</tran>
<tran trig="POINT" target="../../7" cpref="../../../3/2">
<action>BSP_clear();
BSP_insert((int)'0');
BSP_insert((int)'.');</action>
2016-12-01 10:31:49 -05:00
<tran_glyph conn="49,70,2,0,5">
2016-09-01 11:58:57 -04:00
<action box="0,0,6,2"/>
</tran_glyph>
</tran>
<tran trig="OPER">
<choice target="../../../7" cpref="../../../../3/3">
<guard brief="e-&gt;key == '-'">Q_EVT_CAST(CalcEvt)-&gt;key_code == KEY_MINUS</guard>
2016-12-01 10:31:49 -05:00
<choice_glyph conn="34,66,5,0,33,9">
2016-09-01 11:58:57 -04:00
<action box="1,0,11,2"/>
</choice_glyph>
</choice>
<choice>
<guard>else</guard>
<choice_glyph conn="34,66,4,-1,-4,4">
<action box="1,-3,6,2"/>
</choice_glyph>
</choice>
<tran_glyph conn="26,66,3,-1,8">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
<state_glyph node="26,56,32,14">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state name="error">
<entry>BSP_message(&quot;error-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;error-EXIT;&quot;);</exit>
<state_glyph node="11,56,9,8">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<smstate name="operand2" submachine="../../3">
<xpseg xpref="../../../3/4" target="../../5">
<action>BSP_message(&quot;operand2-XP:ce;&quot;);</action>
<xpseg_glyph conn="84,83,1,1,4,-21,-30">
<action box="1,0,10,2"/>
</xpseg_glyph>
</xpseg>
<tran trig="OPER">
<choice target="../../../6">
<guard>else</guard>
<choice_glyph conn="6,67,4,3,-5,5">
<action box="0,-4,6,2"/>
</choice_glyph>
</choice>
<choice target="../../../5">
<guard brief="BSP_eval()">BSP_eval(me-&gt;m_op1, me-&gt;m_oper, BSP_get_value())</guard>
<choice_glyph conn="6,67,5,3,16,-5,4">
<action box="1,1,10,2"/>
</choice_glyph>
</choice>
<tran_glyph conn="8,80,3,-1,-2,-13">
<action box="-2,-2,8,2"/>
</tran_glyph>
</tran>
<tran trig="EQUALS">
<choice target="../../../6">
<guard>else</guard>
<choice_glyph conn="4,58,5,3,7">
<action box="1,0,6,2"/>
</choice_glyph>
</choice>
<choice target="../../../3/5">
<guard brief="BSP_eval()">BSP_eval(me-&gt;m_op1, me-&gt;m_oper, BSP_get_value())</guard>
<choice_glyph conn="4,58,4,3,-34,10">
<action box="0,-4,10,2"/>
</choice_glyph>
</choice>
<tran_glyph conn="8,84,3,-1,-4,-26">
<action box="-4,-2,8,2"/>
</tran_glyph>
</tran>
<smstate_glyph node="8,76,76,12"/>
</smstate>
<state_glyph node="2,4,90,86">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state name="final">
<entry>BSP_message(&quot;final-ENTRY;&quot;);
BSP_exit();</entry>
<state_glyph node="2,92,17,6">
<entry box="1,2,5,2"/>
</state_glyph>
</state>
<submachine name="operand">
<entry>BSP_message(&quot;operand-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;operand-EXIT;&quot;);</exit>
2016-12-01 10:31:49 -05:00
<epseg name="zero" target="../7">
2016-09-01 11:58:57 -04:00
<action>BSP_message(&quot;operand::zero-EP;&quot;);</action>
<epseg_glyph conn="11,2,0,0,8">
<name box="1,-2,10,2"/>
<action box="1,0,10,2"/>
</epseg_glyph>
</epseg>
2016-12-01 10:31:49 -05:00
<epseg name="intgr" target="../8">
2016-09-01 11:58:57 -04:00
<action>BSP_message(&quot;operand::intgr-EP;&quot;);</action>
<epseg_glyph conn="29,2,0,0,8">
<name box="1,-2,10,2"/>
<action box="1,0,10,2"/>
</epseg_glyph>
</epseg>
2016-12-01 10:31:49 -05:00
<epseg name="frac" target="../9">
2016-09-01 11:58:57 -04:00
<action>BSP_message(&quot;operand::frac-EP;&quot;);</action>
<epseg_glyph conn="47,2,0,0,8">
<name box="1,-2,10,2"/>
<action box="1,0,10,2"/>
</epseg_glyph>
</epseg>
2016-12-01 10:31:49 -05:00
<epseg name="neg" target="../10">
2016-09-01 11:58:57 -04:00
<action>BSP_message(&quot;operand::neg-EP;&quot;);</action>
<epseg_glyph conn="67,2,0,0,8">
<name box="1,-2,10,2"/>
<action box="1,0,10,2"/>
</epseg_glyph>
</epseg>
<xp name="ce">
<xp_glyph point="86,20,1">
<name box="-3,-3,5,2"/>
</xp_glyph>
</xp>
2016-12-01 10:31:49 -05:00
<initial target="../7">
2016-09-01 11:58:57 -04:00
<action>BSP_message(&quot;operand-INIT;&quot;);</action>
<initial_glyph conn="20,6,5,0,-6,4">
<action box="0,-2,10,2"/>
</initial_glyph>
</initial>
2016-12-01 10:31:49 -05:00
<tran trig="CE" target=".." cpref="../4">
2016-09-01 11:58:57 -04:00
<action>BSP_message(&quot;operand::CE;&quot;);
BSP_clear();</action>
2016-12-01 10:31:49 -05:00
<tran_glyph conn="80,32,2,1,-12,5">
2016-09-01 11:58:57 -04:00
<action box="0,-2,10,2"/>
</tran_glyph>
</tran>
<state name="zero">
<entry>BSP_message(&quot;operand::zero-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;operand::zero-EXIT;&quot;);</exit>
<tran trig="DIGIT_0">
<action>;</action>
<tran_glyph conn="4,21,3,-1,10">
<action box="0,-2,7,2"/>
</tran_glyph>
</tran>
2016-12-01 10:31:49 -05:00
<tran trig="DIGIT_1_9" target="../../8">
2016-09-01 11:58:57 -04:00
<action>BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
<tran_glyph conn="4,18,3,3,16,-6,2">
<action box="0,-2,9,2"/>
</tran_glyph>
</tran>
2016-12-01 10:31:49 -05:00
<tran trig="POINT" target="../../9">
2016-09-01 11:58:57 -04:00
<action>BSP_insert((int)'0');
BSP_insert((int)'.');</action>
<tran_glyph conn="6,23,2,2,2,40,-2">
<action box="1,0,6,2"/>
</tran_glyph>
</tran>
<state_glyph node="4,10,14,13">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state name="intgr">
<entry>BSP_message(&quot;operand::intgr-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;operand::intgr-EXIT;&quot;);</exit>
2016-12-01 10:31:49 -05:00
<tran trig="POINT" target="../../9">
2016-09-01 11:58:57 -04:00
<action>BSP_insert((int)'.');</action>
<tran_glyph conn="22,18,3,3,16,-6,2">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
<tran trig="DIGIT_0, DIGIT_1_9">
<action>BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
<tran_glyph conn="22,21,3,-1,10">
<action box="0,-2,14,2"/>
</tran_glyph>
</tran>
<state_glyph node="22,10,14,13">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state name="frac">
<entry>BSP_message(&quot;operand::frac-ENTRY;&quot;);</entry>
<exit>BSP_message(&quot;operand::frac-EXIT;&quot;);</exit>
<tran trig="POINT">
<action>;</action>
<tran_glyph conn="40,21,3,-1,10">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
<tran trig="DIGIT_0, DIGIT_1_9">
<action>BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
<tran_glyph conn="40,18,3,-1,10">
<action box="0,-2,15,2"/>
</tran_glyph>
</tran>
<state_glyph node="40,10,14,13">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<state name="neg">
<entry>BSP_message(&quot;operand::neg-ENTRY;&quot;);
BSP_negate();</entry>
<exit>BSP_message(&quot;operand::neg-EXIT;&quot;);</exit>
2016-12-01 10:31:49 -05:00
<tran trig="DIGIT_0" target="../../7">
2016-09-01 11:58:57 -04:00
<action>BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
<tran_glyph conn="58,23,2,2,4,-44,-4">
<action box="0,0,6,2"/>
</tran_glyph>
</tran>
2016-12-01 10:31:49 -05:00
<tran trig="DIGIT_1_9" target="../../8">
2016-09-01 11:58:57 -04:00
<action>BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
<tran_glyph conn="65,23,2,2,5,-35,-5">
<action box="0,0,9,2"/>
</tran_glyph>
</tran>
2016-12-01 10:31:49 -05:00
<tran trig="POINT" target="../../9">
2016-09-01 11:58:57 -04:00
<action>BSP_insert(Q_EVT_CAST(CalcEvt)-&gt;key_code);</action>
<tran_glyph conn="73,23,2,2,6,-25,-6">
<action box="1,0,6,2"/>
</tran_glyph>
</tran>
<tran trig="OPER">
<choice>
<guard>else</guard>
<choice_glyph conn="66,18,4,-1,-4,8">
<action box="1,-4,6,2"/>
</choice_glyph>
</choice>
<choice>
<guard brief="e-&gt;key == '-'">Q_EVT_CAST(CalcEvt)-&gt;key_code == KEY_MINUS</guard>
<action>;</action>
<choice_glyph conn="66,18,5,-1,8">
<action box="1,0,11,2"/>
</choice_glyph>
</choice>
<tran_glyph conn="56,18,3,-1,10">
<action box="0,-2,6,2"/>
</tran_glyph>
</tran>
<state_glyph node="56,10,22,13">
<entry box="1,2,5,2"/>
<exit box="1,4,5,2"/>
</state_glyph>
</state>
<submachine_diagram size="84,30">
<entry box="1,2,6,2"/>
<exit box="1,4,6,2"/>
</submachine_diagram>
</submachine>
<state_diagram size="96,100"/>
</statechart>
</class>
</package>
<directory name=".">
<file name="calc1_sub.h">
<text>#ifndef calc1_sub_h
#define calc1_sub_h
enum CalcSignals {
C_SIG = QP::Q_USER_SIG,
CE_SIG,
DIGIT_0_SIG,
DIGIT_1_9_SIG,
POINT_SIG,
OPER_SIG,
EQUALS_SIG,
OFF_SIG
};
$declare(Events::CalcEvt)
extern QP::QMsm * const the_calc; // &quot;opaque&quot; pointer to calculator MSM
#endif // calc1_sub_h</text>
</file>
<file name="calc1_sub.cpp">
<text>#include &quot;qpcpp.h&quot; // QP/C++
#include &quot;bsp.h&quot; // board support package
#include &quot;calc1_sub.h&quot; // application
$declare(SMs::Calc)
static Calc l_calc; // the only instance of the Calc class
// global-scope definitions --------------------------------------
QP::QMsm * const the_calc = &amp;l_calc; // &quot;opaque&quot; pointer to MSM
$define(SMs::Calc)</text>
</file>
</directory>
</model>