mirror of
https://github.com/QuantumLeaps/qpcpp.git
synced 2025-01-28 06:02:56 +08:00
298 lines
9.9 KiB
XML
298 lines
9.9 KiB
XML
<?xml version="1.0" encoding="UTF-8"?>
|
|
<model version="4.0.0" links="0">
|
|
<documentation>Dining Philosopher Problem example
|
|
|
|
NOTE: Requries QP5</documentation>
|
|
<framework name="qpcpp"/>
|
|
<package name="Events" stereotype="0x01">
|
|
<class name="SetEvt" superclass="qpcpp::QEvt">
|
|
<attribute name="digit" type="uint8_t" visibility="0x00" properties="0x00"/>
|
|
</class>
|
|
<class name="TimeEvt" superclass="qpcpp::QEvt">
|
|
<attribute name="current_time" type="uint32_t" visibility="0x00" properties="0x00"/>
|
|
</class>
|
|
</package>
|
|
<package name="Components" stereotype="0x02">
|
|
<class name="Alarm" superclass="qpcpp::QHsm">
|
|
<documentation>Alarm "Orthogonal Component"</documentation>
|
|
<attribute name="m_alarm_time" type="uint32_t" visibility="0x02" properties="0x00"/>
|
|
<operation name="Alarm" type="" visibility="0x00" properties="0x00">
|
|
<code> : QHsm(Q_STATE_CAST(&Alarm::initial))</code>
|
|
</operation>
|
|
<statechart>
|
|
<initial target="../1">
|
|
<action>me->m_alarm_time = 12U*60U;
|
|
(void)e; // unused parameter</action>
|
|
<initial_glyph conn="2,3,5,1,36,4,-4">
|
|
<action box="0,-2,6,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<state name="off">
|
|
<entry>// while in the off state, the alarm is kept in decimal format
|
|
me->m_alarm_time = (me->m_alarm_time/60)*100 + me->m_alarm_time%60;
|
|
BSP_showTime24H("*** Alarm OFF ", me->m_alarm_time, 100U);</entry>
|
|
<exit>// upon exit, the alarm is converted to binary format
|
|
me->m_alarm_time = (me->m_alarm_time/100U)*60U + me->m_alarm_time%100U;</exit>
|
|
<tran trig="ALARM_ON">
|
|
<choice target="../../../2">
|
|
<guard brief="alarm in range?">(me->m_alarm_time / 100U < 24U)
|
|
&& (me->m_alarm_time % 100U < 60U)</guard>
|
|
<choice_glyph conn="16,14,5,1,22,12,-4">
|
|
<action box="1,0,13,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<choice>
|
|
<guard brief="else"/>
|
|
<action>me->m_alarm_time = 0U;
|
|
BSP_showTime24H("*** Alarm reset", me->m_alarm_time, 100U);</action>
|
|
<choice_glyph conn="16,14,4,-1,-4,12">
|
|
<action box="0,-4,10,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="2,14,3,-1,14">
|
|
<action box="0,-2,10,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="ALARM_SET">
|
|
<action>// while setting, the alarm is kept in decimal format
|
|
me->m_alarm_time =
|
|
(10U * me->m_alarm_time + Q_EVT_CAST(SetEvt)->digit) % 10000U;
|
|
BSP_showTime24H("*** Alarm reset ", me->m_alarm_time, 100U);</action>
|
|
<tran_glyph conn="2,18,3,-1,14">
|
|
<action box="0,-2,11,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="2,5,32,15">
|
|
<entry box="1,2,6,2"/>
|
|
<exit box="1,4,6,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="on">
|
|
<entry>BSP_showTime24H("*** Alarm ON ", me->m_alarm_time, 60U);</entry>
|
|
<tran trig="ALARM_OFF" target="../../1">
|
|
<tran_glyph conn="2,32,3,1,38,-22,-6">
|
|
<action box="0,-2,14,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="ALARM_SET">
|
|
<action>BSP_showMsg("*** Cannot set Alarm when it is ON");</action>
|
|
<tran_glyph conn="2,36,3,-1,14">
|
|
<action box="0,-2,14,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="TIME">
|
|
<choice>
|
|
<guard>Q_EVT_CAST(TimeEvt)->current_time == me->m_alarm_time</guard>
|
|
<action>BSP_showMsg("ALARM!!!");
|
|
|
|
// asynchronously post the event to the container AO
|
|
APP_alarmClock->POST(Q_NEW(QEvt, ALARM_SIG), this);</action>
|
|
<choice_glyph conn="16,40,5,-1,12">
|
|
<action box="1,0,10,2"/>
|
|
</choice_glyph>
|
|
</choice>
|
|
<tran_glyph conn="2,40,3,-1,14">
|
|
<action box="0,-2,10,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="2,24,32,20">
|
|
<entry box="1,2,5,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_diagram size="46,48"/>
|
|
</statechart>
|
|
</class>
|
|
<class name="AlarmClock" superclass="qpcpp::QActive">
|
|
<documentation>Alarm clock "Container"</documentation>
|
|
<attribute name="m_current_time" type="uint32_t" visibility="0x02" properties="0x00"/>
|
|
<attribute name="m_alarm" type="Alarm" visibility="0x02" properties="0x00"/>
|
|
<attribute name="m_timeEvt" type="QTimeEvt" visibility="0x00" properties="0x00"/>
|
|
<operation name="AlarmClock" type="" visibility="0x00" properties="0x00">
|
|
<code>: QActive(Q_STATE_CAST(&AlarmClock::initial)),
|
|
m_alarm(), // orthogonal component ctor
|
|
m_timeEvt(this, TICK_SIG, 0U)</code>
|
|
</operation>
|
|
<statechart>
|
|
<initial target="../1">
|
|
<action>(void)e; // unused parameter
|
|
me->m_current_time = 0U;
|
|
|
|
// (!) trigger the initial transition in the component
|
|
me->m_alarm.init();</action>
|
|
<initial_glyph conn="2,4,5,1,44,4,-2">
|
|
<action box="0,-2,6,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<state name="timekeeping">
|
|
<entry>// periodic timeout every second
|
|
me->m_timeEvt.armX(BSP_TICKS_PER_SEC, BSP_TICKS_PER_SEC);</entry>
|
|
<exit>me->m_timeEvt.disarm();</exit>
|
|
<initial target="../6">
|
|
<initial_glyph conn="4,13,5,1,36,27,-4">
|
|
<action box="0,-2,10,2"/>
|
|
</initial_glyph>
|
|
</initial>
|
|
<tran trig="CLOCK_24H" target="../6">
|
|
<tran_glyph conn="2,16,3,1,36,22,-2">
|
|
<action box="0,-2,10,4"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="CLOCK_12H" target="../7">
|
|
<tran_glyph conn="2,18,3,1,40,34,-6">
|
|
<action box="0,-2,10,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="ALARM">
|
|
<action>BSP_showMsg("Wake up!!!");</action>
|
|
<tran_glyph conn="2,28,3,-1,18">
|
|
<action box="0,-2,10,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="ALARM_SET, ALARM_ON, ALARM_OFF">
|
|
<action>// (!) synchronously dispatch to the orthogonal component
|
|
me->m_alarm.dispatch(e);</action>
|
|
<tran_glyph conn="2,22,3,-1,18">
|
|
<action box="0,-2,11,6"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<tran trig="TERMINATE" target="../../2">
|
|
<action>BSP_showMsg("--> final");</action>
|
|
<tran_glyph conn="2,32,3,1,44,38,-13">
|
|
<action box="0,-2,10,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state name="mode24h">
|
|
<entry>BSP_showMsg("*** 24-hour mode");</entry>
|
|
<tran trig="TICK">
|
|
<action>// roll over in 24-hr mode?
|
|
if (++me->m_current_time == 24U*60U) {
|
|
me->m_current_time = 0U;
|
|
}
|
|
BSP_showTime24H("", me->m_current_time, 60U);
|
|
|
|
TimeEvt pe; // temporary synchronous event for the component
|
|
pe.sig = TIME_SIG;
|
|
pe.current_time = me->m_current_time;
|
|
|
|
// (!) synchronously dispatch to the orthogonal component
|
|
me->m_alarm.dispatch(&pe);</action>
|
|
<tran_glyph conn="4,44,3,-1,16">
|
|
<action box="0,-2,8,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="4,36,32,12">
|
|
<entry box="1,2,27,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="mode12h">
|
|
<entry>BSP_showMsg("*** 12-hour mode");</entry>
|
|
<tran trig="TICK">
|
|
<action>// roll over in 12-hr mode?
|
|
if (++me->m_current_time == 12U*60U) {
|
|
me->m_current_time = 0U;
|
|
}
|
|
BSP_showTime12H("", me->m_current_time, 60U);
|
|
|
|
TimeEvt pe; // temporary synchronous event for the component
|
|
pe.sig = TIME_SIG;
|
|
pe.current_time = me->m_current_time;
|
|
|
|
// (!) synchronously dispatch to the orthogonal component
|
|
me->m_alarm.dispatch(&pe);</action>
|
|
<tran_glyph conn="4,58,3,-1,16">
|
|
<action box="0,-2,8,2"/>
|
|
</tran_glyph>
|
|
</tran>
|
|
<state_glyph node="4,50,32,12">
|
|
<entry box="1,2,17,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_glyph node="2,6,42,58">
|
|
<entry box="1,2,6,2"/>
|
|
<exit box="1,4,6,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state name="final">
|
|
<entry brief="terminate">BSP_showMsg("Bye! Bye!");
|
|
QF::stop(); // terminate the application</entry>
|
|
<state_glyph node="2,68,31,8">
|
|
<entry box="1,2,11,2"/>
|
|
</state_glyph>
|
|
</state>
|
|
<state_diagram size="50,80"/>
|
|
</statechart>
|
|
</class>
|
|
<attribute name="APP_alarmClock" type="QActive * const" visibility="0x00" properties="0x00">
|
|
<documentation>Opaque pointer to the single instance of the AlarmClock AO</documentation>
|
|
</attribute>
|
|
</package>
|
|
<directory name=".">
|
|
<file name="alarm.h">
|
|
<text>#ifndef alarm_h
|
|
#define alarm_h
|
|
|
|
$declare(Components::Alarm)
|
|
|
|
#endif // alarm_h</text>
|
|
</file>
|
|
<file name="alarm.cpp">
|
|
<text>#include "qpcpp.h"
|
|
#include "bsp.h"
|
|
#include "alarm.h"
|
|
#include "clock.h"
|
|
|
|
Q_DEFINE_THIS_FILE
|
|
|
|
// Alarm component --------------------
|
|
$define(Components::Alarm)</text>
|
|
</file>
|
|
<file name="clock.h">
|
|
<text>#ifndef clock_h
|
|
#define clock_h
|
|
|
|
using namespace QP;
|
|
|
|
enum AlarmClockSignals {
|
|
TICK_SIG = Q_USER_SIG, // time tick event
|
|
ALARM_SET_SIG, // set the alarm
|
|
ALARM_ON_SIG, // turn the alarm on
|
|
ALARM_OFF_SIG, // turn the alarm off
|
|
ALARM_SIG, // alarm event from Alarm component to AlarmClock container
|
|
CLOCK_12H_SIG, // set the clock in 12H mode
|
|
CLOCK_24H_SIG, // set the clock in 24H mode
|
|
TIME_SIG, // time event sent to Alarm (contains current time)
|
|
TERMINATE_SIG // terminate the application
|
|
};
|
|
|
|
$declare(Events::SetEvt)
|
|
$declare(Events::TimeEvt)
|
|
|
|
$declare(Components::APP_alarmClock)
|
|
|
|
#endif // clock_h</text>
|
|
</file>
|
|
<file name="clock.cpp">
|
|
<text>#include "qpcpp.h"
|
|
#include "bsp.h"
|
|
#include "alarm.h"
|
|
#include "clock.h"
|
|
|
|
#include <stdio.h>
|
|
|
|
Q_DEFINE_THIS_FILE
|
|
|
|
// Active object class -------------------------------------------------------
|
|
$declare(Components::AlarmClock)
|
|
|
|
// Local objects -------------------------------------------------------------
|
|
static AlarmClock l_alarmClock; // the single instance of the AO
|
|
|
|
// Global-scope objects ------------------------------------------------------
|
|
QActive * const APP_alarmClock = &l_alarmClock; // "opaque" AO pointer
|
|
|
|
//............................................................................
|
|
$define(Components::AlarmClock)</text>
|
|
</file>
|
|
</directory>
|
|
</model>
|