comp.qm 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354
  1. <?xml version="1.0" encoding="UTF-8"?>
  2. <model version="5.2.4" links="1">
  3. <documentation>&quot;Orthogonal Component&quot; example</documentation>
  4. <!--${qpc}-->
  5. <framework name="qpc"/>
  6. <!--${Events}-->
  7. <package name="Events" stereotype="0x01">
  8. <!--${Events::SetEvt}-->
  9. <class name="SetEvt" superclass="qpc::QEvt">
  10. <!--${Events::SetEvt::digit}-->
  11. <attribute name="digit" type="uint8_t" visibility="0x00" properties="0x00"/>
  12. </class>
  13. <!--${Events::TimeEvt}-->
  14. <class name="TimeEvt" superclass="qpc::QEvt">
  15. <!--${Events::TimeEvt::current_time}-->
  16. <attribute name="current_time" type="uint32_t" visibility="0x00" properties="0x00"/>
  17. </class>
  18. </package>
  19. <!--${Components}-->
  20. <package name="Components" stereotype="0x02">
  21. <!--${Components::Alarm}-->
  22. <class name="Alarm" superclass="qpc::QHsm">
  23. <documentation>Alarm &quot;Orthogonal Component&quot;</documentation>
  24. <!--${Components::Alarm::alarm_time}-->
  25. <attribute name="alarm_time" type="uint32_t" visibility="0x02" properties="0x00"/>
  26. <!--${Components::Alarm::ctor}-->
  27. <operation name="ctor" type="void" visibility="0x00" properties="0x00">
  28. <code>QHsm_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;Alarm_initial));</code>
  29. </operation>
  30. <!--${Components::Alarm::SM}-->
  31. <statechart properties="0x01">
  32. <!--${Components::Alarm::SM::initial}-->
  33. <initial target="../1">
  34. <action>me-&gt;alarm_time = 12U*60U;
  35. (void)par; /* unused parameter */</action>
  36. <initial_glyph conn="2,3,5,1,36,4,-4">
  37. <action box="0,-2,6,2"/>
  38. </initial_glyph>
  39. </initial>
  40. <!--${Components::Alarm::SM::off}-->
  41. <state name="off">
  42. <entry>/* while in the off state, the alarm is kept in decimal format */
  43. me-&gt;alarm_time = (me-&gt;alarm_time/60)*100 + me-&gt;alarm_time%60;
  44. BSP_showTime24H(&quot;*** Alarm OFF &quot;, me-&gt;alarm_time, 100U);</entry>
  45. <exit>/* upon exit, the alarm is converted to binary format */
  46. me-&gt;alarm_time = (me-&gt;alarm_time/100U)*60U + me-&gt;alarm_time%100U;</exit>
  47. <!--${Components::Alarm::SM::off::ALARM_ON}-->
  48. <tran trig="ALARM_ON">
  49. <!--${Components::Alarm::SM::off::ALARM_ON::[alarminrange?]}-->
  50. <choice target="../../../2">
  51. <guard brief="alarm in range?">(me-&gt;alarm_time / 100U &lt; 24U)
  52. &amp;&amp; (me-&gt;alarm_time % 100U &lt; 60U)</guard>
  53. <choice_glyph conn="16,14,5,1,22,12,-4">
  54. <action box="1,0,13,2"/>
  55. </choice_glyph>
  56. </choice>
  57. <!--${Components::Alarm::SM::off::ALARM_ON::[else]}-->
  58. <choice>
  59. <guard brief="else"/>
  60. <action>me-&gt;alarm_time = 0U;
  61. BSP_showTime24H(&quot;*** Alarm reset&quot;, me-&gt;alarm_time, 100U);</action>
  62. <choice_glyph conn="16,14,4,-1,-4,12">
  63. <action box="0,-4,10,2"/>
  64. </choice_glyph>
  65. </choice>
  66. <tran_glyph conn="2,14,3,-1,14">
  67. <action box="0,-2,10,2"/>
  68. </tran_glyph>
  69. </tran>
  70. <!--${Components::Alarm::SM::off::ALARM_SET}-->
  71. <tran trig="ALARM_SET">
  72. <action>/* while setting, the alarm is kept in decimal format */
  73. me-&gt;alarm_time = (10U * me-&gt;alarm_time
  74. + ((SetEvt const *)e)-&gt;digit) % 10000U;
  75. BSP_showTime24H(&quot;*** Alarm reset &quot;, me-&gt;alarm_time, 100U);</action>
  76. <tran_glyph conn="2,18,3,-1,14">
  77. <action box="0,-2,11,2"/>
  78. </tran_glyph>
  79. </tran>
  80. <state_glyph node="2,5,32,15">
  81. <entry box="1,2,6,2"/>
  82. <exit box="1,4,6,2"/>
  83. </state_glyph>
  84. </state>
  85. <!--${Components::Alarm::SM::on}-->
  86. <state name="on">
  87. <entry>BSP_showTime24H(&quot;*** Alarm ON &quot;, me-&gt;alarm_time, 60U);</entry>
  88. <!--${Components::Alarm::SM::on::ALARM_OFF}-->
  89. <tran trig="ALARM_OFF" target="../../1">
  90. <tran_glyph conn="2,32,3,1,38,-22,-6">
  91. <action box="0,-2,14,2"/>
  92. </tran_glyph>
  93. </tran>
  94. <!--${Components::Alarm::SM::on::ALARM_SET}-->
  95. <tran trig="ALARM_SET">
  96. <action>BSP_showMsg(&quot;*** Cannot set Alarm when it is ON&quot;);</action>
  97. <tran_glyph conn="2,36,3,-1,14">
  98. <action box="0,-2,14,2"/>
  99. </tran_glyph>
  100. </tran>
  101. <!--${Components::Alarm::SM::on::TIME}-->
  102. <tran trig="TIME">
  103. <!--${Components::Alarm::SM::on::TIME::[Q_EVT_CAST(TimeEvt)->current_ti~}-->
  104. <choice>
  105. <guard>Q_EVT_CAST(TimeEvt)-&gt;current_time == me-&gt;alarm_time</guard>
  106. <action>BSP_showMsg(&quot;ALARM!!!&quot;);
  107. /* asynchronously post the event to the container AO */
  108. QACTIVE_POST(APP_alarmClock, Q_NEW(QEvt, ALARM_SIG), me);</action>
  109. <choice_glyph conn="16,40,5,-1,12">
  110. <action box="1,0,10,2"/>
  111. </choice_glyph>
  112. </choice>
  113. <tran_glyph conn="2,40,3,-1,14">
  114. <action box="0,-2,10,2"/>
  115. </tran_glyph>
  116. </tran>
  117. <state_glyph node="2,24,32,20">
  118. <entry box="1,2,5,2"/>
  119. </state_glyph>
  120. </state>
  121. <state_diagram size="46,48"/>
  122. </statechart>
  123. </class>
  124. <!--${Components::AlarmClock}-->
  125. <class name="AlarmClock" superclass="qpc::QActive">
  126. <documentation>Alarm clock &quot;Container&quot;</documentation>
  127. <!--${Components::AlarmClock::current_time}-->
  128. <attribute name="current_time" type="uint32_t" visibility="0x02" properties="0x00"/>
  129. <!--${Components::AlarmClock::alarm}-->
  130. <attribute name="alarm" type="Alarm" visibility="0x02" properties="0x00"/>
  131. <!--${Components::AlarmClock::timeEvt}-->
  132. <attribute name="timeEvt" type="QTimeEvt" visibility="0x00" properties="0x00"/>
  133. <!--${Components::AlarmClock::SM}-->
  134. <statechart properties="0x01">
  135. <!--${Components::AlarmClock::SM::initial}-->
  136. <initial target="../1">
  137. <action>(void)par; /* unused parameter */
  138. me-&gt;current_time = 0U;
  139. /* (!) trigger the initial transition in the component */
  140. QHSM_INIT((QHsm *)&amp;me-&gt;alarm, (void *)0, me-&gt;super.prio);</action>
  141. <initial_glyph conn="2,4,5,1,44,4,-2">
  142. <action box="0,-2,6,2"/>
  143. </initial_glyph>
  144. </initial>
  145. <!--${Components::AlarmClock::SM::timekeeping}-->
  146. <state name="timekeeping">
  147. <entry>/* periodic timeout every second */
  148. QTimeEvt_armX(&amp;me-&gt;timeEvt, BSP_TICKS_PER_SEC,
  149. BSP_TICKS_PER_SEC);</entry>
  150. <exit>QTimeEvt_disarm(&amp;me-&gt;timeEvt);</exit>
  151. <!--${Components::AlarmClock::SM::timekeeping::initial}-->
  152. <initial target="../6">
  153. <initial_glyph conn="4,13,5,1,36,27,-4">
  154. <action box="0,-2,10,2"/>
  155. </initial_glyph>
  156. </initial>
  157. <!--${Components::AlarmClock::SM::timekeeping::CLOCK_24H}-->
  158. <tran trig="CLOCK_24H" target="../6">
  159. <tran_glyph conn="2,16,3,1,36,22,-2">
  160. <action box="0,-2,10,4"/>
  161. </tran_glyph>
  162. </tran>
  163. <!--${Components::AlarmClock::SM::timekeeping::CLOCK_12H}-->
  164. <tran trig="CLOCK_12H" target="../7">
  165. <tran_glyph conn="2,18,3,1,40,34,-6">
  166. <action box="0,-2,10,2"/>
  167. </tran_glyph>
  168. </tran>
  169. <!--${Components::AlarmClock::SM::timekeeping::ALARM}-->
  170. <tran trig="ALARM">
  171. <action>BSP_showMsg(&quot;Wake up!!!&quot;);</action>
  172. <tran_glyph conn="2,28,3,-1,18">
  173. <action box="0,-2,10,2"/>
  174. </tran_glyph>
  175. </tran>
  176. <!--${Components::AlarmClock::SM::timekeeping::ALARM_SET, ALARM_ON, ALARM_OFF}-->
  177. <tran trig="ALARM_SET, ALARM_ON, ALARM_OFF">
  178. <action>/* (!) synchronously dispatch to the orthogonal component */
  179. QHSM_DISPATCH((QHsm *)&amp;me-&gt;alarm, e, me-&gt;super.prio);</action>
  180. <tran_glyph conn="2,22,3,-1,18">
  181. <action box="0,-2,11,6"/>
  182. </tran_glyph>
  183. </tran>
  184. <!--${Components::AlarmClock::SM::timekeeping::TERMINATE}-->
  185. <tran trig="TERMINATE" target="../../2">
  186. <action>BSP_showMsg(&quot;--&gt; final&quot;);</action>
  187. <tran_glyph conn="2,32,3,1,44,38,-13">
  188. <action box="0,-2,10,2"/>
  189. </tran_glyph>
  190. </tran>
  191. <!--${Components::AlarmClock::SM::timekeeping::mode24h}-->
  192. <state name="mode24h">
  193. <entry>BSP_showMsg(&quot;*** 24-hour mode&quot;);</entry>
  194. <!--${Components::AlarmClock::SM::timekeeping::mode24h::TICK}-->
  195. <tran trig="TICK">
  196. <action>TimeEvt pe; /* temporary synchronous event for the component */
  197. /* roll over in 24-hr mode? */
  198. if (++me-&gt;current_time == 24U*60U) {
  199. me-&gt;current_time = 0U;
  200. }
  201. BSP_showTime24H(&quot;&quot;, me-&gt;current_time, 60U);
  202. pe.super.sig = TIME_SIG;
  203. pe.current_time = me-&gt;current_time;
  204. /* (!) synchronously dispatch to the orthogonal component */
  205. QHSM_DISPATCH(&amp;me-&gt;alarm.super, &amp;pe.super, me-&gt;super.prio);</action>
  206. <tran_glyph conn="4,44,3,-1,16">
  207. <action box="0,-2,8,2"/>
  208. </tran_glyph>
  209. </tran>
  210. <state_glyph node="4,36,32,12">
  211. <entry box="1,2,27,2"/>
  212. </state_glyph>
  213. </state>
  214. <!--${Components::AlarmClock::SM::timekeeping::mode12h}-->
  215. <state name="mode12h">
  216. <entry>BSP_showMsg(&quot;*** 12-hour mode&quot;);</entry>
  217. <!--${Components::AlarmClock::SM::timekeeping::mode12h::TICK}-->
  218. <tran trig="TICK">
  219. <action>TimeEvt pe; /* temporary synchronous event for the component */
  220. /* roll over in 12-hr mode? */
  221. if (++me-&gt;current_time == 12U*60U) {
  222. me-&gt;current_time = 0U;
  223. }
  224. BSP_showTime12H(&quot;&quot;, me-&gt;current_time, 60U);
  225. pe.super.sig = TIME_SIG;
  226. pe.current_time = me-&gt;current_time;
  227. /* (!) synchronously dispatch to the orthogonal component */
  228. QHSM_DISPATCH(&amp;me-&gt;alarm.super, &amp;pe.super, me-&gt;super.prio);</action>
  229. <tran_glyph conn="4,58,3,-1,16">
  230. <action box="0,-2,8,2"/>
  231. </tran_glyph>
  232. </tran>
  233. <state_glyph node="4,50,32,12">
  234. <entry box="1,2,17,2"/>
  235. </state_glyph>
  236. </state>
  237. <state_glyph node="2,6,42,58">
  238. <entry box="1,2,6,2"/>
  239. <exit box="1,4,6,2"/>
  240. </state_glyph>
  241. </state>
  242. <!--${Components::AlarmClock::SM::final}-->
  243. <state name="final">
  244. <entry brief="terminate">QF_stop(); /* terminate the application */</entry>
  245. <state_glyph node="2,68,31,8">
  246. <entry box="1,2,11,2"/>
  247. </state_glyph>
  248. </state>
  249. <state_diagram size="50,80"/>
  250. </statechart>
  251. </class>
  252. <!--${Components::APP_alarmClock}-->
  253. <attribute name="APP_alarmClock" type="QActive * const" visibility="0x00" properties="0x00">
  254. <documentation>Opaque pointer to the single inst of the AlarmClock AO</documentation>
  255. <code>= &amp;l_alarmClock.super;</code>
  256. </attribute>
  257. <!--${Components::AlarmClock_ctor}-->
  258. <operation name="AlarmClock_ctor" type="void" visibility="0x00" properties="0x00">
  259. <code>AlarmClock * const me = &amp;l_alarmClock;
  260. QActive_ctor(&amp;me-&gt;super, Q_STATE_CAST(&amp;AlarmClock_initial));
  261. Alarm_ctor(&amp;me-&gt;alarm); /* orthogonal component ctor */
  262. /* private time event ctor */
  263. QTimeEvt_ctorX(&amp;me-&gt;timeEvt, &amp;me-&gt;super, TICK_SIG, 0U);</code>
  264. </operation>
  265. </package>
  266. <!--${.}-->
  267. <directory name=".">
  268. <!--${.::alarm.h}-->
  269. <file name="alarm.h">
  270. <text>#ifndef ALARM_H
  271. #define ALARM_H
  272. $declare${Components::Alarm}
  273. $declare${Components::Alarm::ctor}
  274. #endif /* ALARM_H */
  275. </text>
  276. </file>
  277. <!--${.::alarm.c}-->
  278. <file name="alarm.c">
  279. <text>#include &quot;qpc.h&quot;
  280. #include &quot;bsp.h&quot;
  281. #include &quot;alarm.h&quot;
  282. #include &quot;clock.h&quot;
  283. //Q_DEFINE_THIS_FILE
  284. /* Alarm component --------------------*/
  285. $define${Components::Alarm}
  286. </text>
  287. </file>
  288. <!--${.::clock.h}-->
  289. <file name="clock.h">
  290. <text>#ifndef CLOCK_H
  291. #define CLOCK_H
  292. enum AlarmClockSignals {
  293. TICK_SIG = Q_USER_SIG, /* time tick event */
  294. ALARM_SET_SIG, /* set the alarm */
  295. ALARM_ON_SIG, /* turn the alarm on */
  296. ALARM_OFF_SIG, /* turn the alarm off */
  297. ALARM_SIG, /* alarm event from Alarm component to AlarmClock container */
  298. CLOCK_12H_SIG, /* set the clock in 12H mode */
  299. CLOCK_24H_SIG, /* set the clock in 24H mode */
  300. TIME_SIG, /* time event sent to Alarm (contains current time) */
  301. TERMINATE_SIG /* terminate the application */
  302. };
  303. $declare${Events::SetEvt}
  304. $declare${Events::TimeEvt}
  305. $declare${Components::APP_alarmClock}
  306. $declare${Components::AlarmClock_ctor}
  307. #endif /* CLOCK_H */
  308. </text>
  309. </file>
  310. <!--${.::clock.c}-->
  311. <file name="clock.c">
  312. <text>#include &quot;qpc.h&quot;
  313. #include &quot;bsp.h&quot;
  314. #include &quot;alarm.h&quot;
  315. #include &quot;clock.h&quot;
  316. #include &quot;safe_std.h&quot; /* portable &quot;safe&quot; &lt;stdio.h&gt;/&lt;string.h&gt; facilities */
  317. Q_DEFINE_THIS_FILE
  318. /* Active object class -----------------------------------------------------*/
  319. $declare${Components::AlarmClock}
  320. /* Local objects -----------------------------------------------------------*/
  321. static AlarmClock l_alarmClock; /* the single inst of the AO */
  322. /* Global-scope objects ----------------------------------------------------*/
  323. $define${Components::APP_alarmClock}
  324. $define${Components::AlarmClock_ctor}
  325. /*..........................................................................*/
  326. $define${Components::AlarmClock}
  327. </text>
  328. </file>
  329. </directory>
  330. </model>