| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354 |
- <?xml version="1.0" encoding="UTF-8"?>
- <model version="5.2.4" links="1">
- <documentation>"Orthogonal Component" example</documentation>
- <!--${qpc}-->
- <framework name="qpc"/>
- <!--${Events}-->
- <package name="Events" stereotype="0x01">
- <!--${Events::SetEvt}-->
- <class name="SetEvt" superclass="qpc::QEvt">
- <!--${Events::SetEvt::digit}-->
- <attribute name="digit" type="uint8_t" visibility="0x00" properties="0x00"/>
- </class>
- <!--${Events::TimeEvt}-->
- <class name="TimeEvt" superclass="qpc::QEvt">
- <!--${Events::TimeEvt::current_time}-->
- <attribute name="current_time" type="uint32_t" visibility="0x00" properties="0x00"/>
- </class>
- </package>
- <!--${Components}-->
- <package name="Components" stereotype="0x02">
- <!--${Components::Alarm}-->
- <class name="Alarm" superclass="qpc::QHsm">
- <documentation>Alarm "Orthogonal Component"</documentation>
- <!--${Components::Alarm::alarm_time}-->
- <attribute name="alarm_time" type="uint32_t" visibility="0x02" properties="0x00"/>
- <!--${Components::Alarm::ctor}-->
- <operation name="ctor" type="void" visibility="0x00" properties="0x00">
- <code>QHsm_ctor(&me->super, Q_STATE_CAST(&Alarm_initial));</code>
- </operation>
- <!--${Components::Alarm::SM}-->
- <statechart properties="0x01">
- <!--${Components::Alarm::SM::initial}-->
- <initial target="../1">
- <action>me->alarm_time = 12U*60U;
- (void)par; /* unused parameter */</action>
- <initial_glyph conn="2,3,5,1,36,4,-4">
- <action box="0,-2,6,2"/>
- </initial_glyph>
- </initial>
- <!--${Components::Alarm::SM::off}-->
- <state name="off">
- <entry>/* while in the off state, the alarm is kept in decimal format */
- me->alarm_time = (me->alarm_time/60)*100 + me->alarm_time%60;
- BSP_showTime24H("*** Alarm OFF ", me->alarm_time, 100U);</entry>
- <exit>/* upon exit, the alarm is converted to binary format */
- me->alarm_time = (me->alarm_time/100U)*60U + me->alarm_time%100U;</exit>
- <!--${Components::Alarm::SM::off::ALARM_ON}-->
- <tran trig="ALARM_ON">
- <!--${Components::Alarm::SM::off::ALARM_ON::[alarminrange?]}-->
- <choice target="../../../2">
- <guard brief="alarm in range?">(me->alarm_time / 100U < 24U)
- && (me->alarm_time % 100U < 60U)</guard>
- <choice_glyph conn="16,14,5,1,22,12,-4">
- <action box="1,0,13,2"/>
- </choice_glyph>
- </choice>
- <!--${Components::Alarm::SM::off::ALARM_ON::[else]}-->
- <choice>
- <guard brief="else"/>
- <action>me->alarm_time = 0U;
- BSP_showTime24H("*** Alarm reset", me->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>
- <!--${Components::Alarm::SM::off::ALARM_SET}-->
- <tran trig="ALARM_SET">
- <action>/* while setting, the alarm is kept in decimal format */
- me->alarm_time = (10U * me->alarm_time
- + ((SetEvt const *)e)->digit) % 10000U;
- BSP_showTime24H("*** Alarm reset ", me->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>
- <!--${Components::Alarm::SM::on}-->
- <state name="on">
- <entry>BSP_showTime24H("*** Alarm ON ", me->alarm_time, 60U);</entry>
- <!--${Components::Alarm::SM::on::ALARM_OFF}-->
- <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>
- <!--${Components::Alarm::SM::on::ALARM_SET}-->
- <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>
- <!--${Components::Alarm::SM::on::TIME}-->
- <tran trig="TIME">
- <!--${Components::Alarm::SM::on::TIME::[Q_EVT_CAST(TimeEvt)->current_ti~}-->
- <choice>
- <guard>Q_EVT_CAST(TimeEvt)->current_time == me->alarm_time</guard>
- <action>BSP_showMsg("ALARM!!!");
- /* asynchronously post the event to the container AO */
- QACTIVE_POST(APP_alarmClock, Q_NEW(QEvt, ALARM_SIG), me);</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>
- <!--${Components::AlarmClock}-->
- <class name="AlarmClock" superclass="qpc::QActive">
- <documentation>Alarm clock "Container"</documentation>
- <!--${Components::AlarmClock::current_time}-->
- <attribute name="current_time" type="uint32_t" visibility="0x02" properties="0x00"/>
- <!--${Components::AlarmClock::alarm}-->
- <attribute name="alarm" type="Alarm" visibility="0x02" properties="0x00"/>
- <!--${Components::AlarmClock::timeEvt}-->
- <attribute name="timeEvt" type="QTimeEvt" visibility="0x00" properties="0x00"/>
- <!--${Components::AlarmClock::SM}-->
- <statechart properties="0x01">
- <!--${Components::AlarmClock::SM::initial}-->
- <initial target="../1">
- <action>(void)par; /* unused parameter */
- me->current_time = 0U;
- /* (!) trigger the initial transition in the component */
- QHSM_INIT((QHsm *)&me->alarm, (void *)0, me->super.prio);</action>
- <initial_glyph conn="2,4,5,1,44,4,-2">
- <action box="0,-2,6,2"/>
- </initial_glyph>
- </initial>
- <!--${Components::AlarmClock::SM::timekeeping}-->
- <state name="timekeeping">
- <entry>/* periodic timeout every second */
- QTimeEvt_armX(&me->timeEvt, BSP_TICKS_PER_SEC,
- BSP_TICKS_PER_SEC);</entry>
- <exit>QTimeEvt_disarm(&me->timeEvt);</exit>
- <!--${Components::AlarmClock::SM::timekeeping::initial}-->
- <initial target="../6">
- <initial_glyph conn="4,13,5,1,36,27,-4">
- <action box="0,-2,10,2"/>
- </initial_glyph>
- </initial>
- <!--${Components::AlarmClock::SM::timekeeping::CLOCK_24H}-->
- <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>
- <!--${Components::AlarmClock::SM::timekeeping::CLOCK_12H}-->
- <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>
- <!--${Components::AlarmClock::SM::timekeeping::ALARM}-->
- <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>
- <!--${Components::AlarmClock::SM::timekeeping::ALARM_SET, ALARM_ON, ALARM_OFF}-->
- <tran trig="ALARM_SET, ALARM_ON, ALARM_OFF">
- <action>/* (!) synchronously dispatch to the orthogonal component */
- QHSM_DISPATCH((QHsm *)&me->alarm, e, me->super.prio);</action>
- <tran_glyph conn="2,22,3,-1,18">
- <action box="0,-2,11,6"/>
- </tran_glyph>
- </tran>
- <!--${Components::AlarmClock::SM::timekeeping::TERMINATE}-->
- <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>
- <!--${Components::AlarmClock::SM::timekeeping::mode24h}-->
- <state name="mode24h">
- <entry>BSP_showMsg("*** 24-hour mode");</entry>
- <!--${Components::AlarmClock::SM::timekeeping::mode24h::TICK}-->
- <tran trig="TICK">
- <action>TimeEvt pe; /* temporary synchronous event for the component */
- /* roll over in 24-hr mode? */
- if (++me->current_time == 24U*60U) {
- me->current_time = 0U;
- }
- BSP_showTime24H("", me->current_time, 60U);
- pe.super.sig = TIME_SIG;
- pe.current_time = me->current_time;
- /* (!) synchronously dispatch to the orthogonal component */
- QHSM_DISPATCH(&me->alarm.super, &pe.super, me->super.prio);</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>
- <!--${Components::AlarmClock::SM::timekeeping::mode12h}-->
- <state name="mode12h">
- <entry>BSP_showMsg("*** 12-hour mode");</entry>
- <!--${Components::AlarmClock::SM::timekeeping::mode12h::TICK}-->
- <tran trig="TICK">
- <action>TimeEvt pe; /* temporary synchronous event for the component */
- /* roll over in 12-hr mode? */
- if (++me->current_time == 12U*60U) {
- me->current_time = 0U;
- }
- BSP_showTime12H("", me->current_time, 60U);
- pe.super.sig = TIME_SIG;
- pe.current_time = me->current_time;
- /* (!) synchronously dispatch to the orthogonal component */
- QHSM_DISPATCH(&me->alarm.super, &pe.super, me->super.prio);</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>
- <!--${Components::AlarmClock::SM::final}-->
- <state name="final">
- <entry brief="terminate">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>
- <!--${Components::APP_alarmClock}-->
- <attribute name="APP_alarmClock" type="QActive * const" visibility="0x00" properties="0x00">
- <documentation>Opaque pointer to the single inst of the AlarmClock AO</documentation>
- <code>= &l_alarmClock.super;</code>
- </attribute>
- <!--${Components::AlarmClock_ctor}-->
- <operation name="AlarmClock_ctor" type="void" visibility="0x00" properties="0x00">
- <code>AlarmClock * const me = &l_alarmClock;
- QActive_ctor(&me->super, Q_STATE_CAST(&AlarmClock_initial));
- Alarm_ctor(&me->alarm); /* orthogonal component ctor */
- /* private time event ctor */
- QTimeEvt_ctorX(&me->timeEvt, &me->super, TICK_SIG, 0U);</code>
- </operation>
- </package>
- <!--${.}-->
- <directory name=".">
- <!--${.::alarm.h}-->
- <file name="alarm.h">
- <text>#ifndef ALARM_H
- #define ALARM_H
- $declare${Components::Alarm}
- $declare${Components::Alarm::ctor}
- #endif /* ALARM_H */
- </text>
- </file>
- <!--${.::alarm.c}-->
- <file name="alarm.c">
- <text>#include "qpc.h"
- #include "bsp.h"
- #include "alarm.h"
- #include "clock.h"
- //Q_DEFINE_THIS_FILE
- /* Alarm component --------------------*/
- $define${Components::Alarm}
- </text>
- </file>
- <!--${.::clock.h}-->
- <file name="clock.h">
- <text>#ifndef CLOCK_H
- #define CLOCK_H
- 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}
- $declare${Components::AlarmClock_ctor}
- #endif /* CLOCK_H */
- </text>
- </file>
- <!--${.::clock.c}-->
- <file name="clock.c">
- <text>#include "qpc.h"
- #include "bsp.h"
- #include "alarm.h"
- #include "clock.h"
- #include "safe_std.h" /* portable "safe" <stdio.h>/<string.h> facilities */
- Q_DEFINE_THIS_FILE
- /* Active object class -----------------------------------------------------*/
- $declare${Components::AlarmClock}
- /* Local objects -----------------------------------------------------------*/
- static AlarmClock l_alarmClock; /* the single inst of the AO */
- /* Global-scope objects ----------------------------------------------------*/
- $define${Components::APP_alarmClock}
- $define${Components::AlarmClock_ctor}
- /*..........................................................................*/
- $define${Components::AlarmClock}
- </text>
- </file>
- </directory>
- </model>
|