1 /*****************************************************************************
2 * Model: C:/Documents and Settings/Harry McNally/My Documents/project/arduino/stepper/arduino/stepper/stepper.qm
5 * This file has been generated automatically by QP Modeler (QM).
6 * DO NOT EDIT THIS FILE MANUALLY.
8 * Please visit www.state-machine.com/qm for more information.
9 *****************************************************************************/
11 // Product: Radiotelescope - Stepper Motor Controller
13 // Date: 25 November 2010
15 // +-----------------------+
16 // | d e c i s i o n s |
17 // +-----------------------|
18 // | a n d d e s i g n s |
19 // +-----------------------+
21 // Copyright (C) 2009 Decisions and Designs Pty Ltd. All rights reserved.
23 // This software may be distributed and modified under the terms of the GNU
24 // General Public License version 2 (GPL) as published by the Free Software
25 // Foundation and appearing in the file GPL.TXT included in the packaging of
26 // this file. Please note that GPL Section 2[b] requires that all works based
27 // on this software must also be made publicly available under the terms of
28 // the GPL ("Copyleft").
30 // Contact information:
31 // Decisions and Designs Web site: http://www.decisions-and-designs.com.au
35 #include "radiotelescope.h"
37 #include "serial_command.h"
41 extern MenuSignal menuSignal[];
43 #define UI_TX_BUFFER_LENGTH 80
45 /* encapsulated delcaration of the UI active object ------------------------*/
46 /* $(AOs::UI) ..............................................................*/
47 typedef struct UITag {
52 SerialCommand serialCommand;
53 char txBuffer[UI_TX_BUFFER_LENGTH];
60 QState UI_initial(UI *me);
61 QState UI_User(UI *me);
64 /* global objects ----------------------------------------------------------*/
67 /* Active object definition ------------------------------------------------*/
68 /* $(AOs::UI) ..............................................................*/
69 /* $(AOs::UI::ctor) ........................................................*/
71 QActive_ctor((QActive *)&AO_UI, (QStateHandler)&UI_initial);
72 SerialCommand_ctor(&AO_UI.serialCommand, (QActive *)&AO_UI, menu, menuSignal, AO_UI.txBuffer, UI_TX_BUFFER_LENGTH, 0, 9600);
75 /* $(AOs::UI::Statechart) ..................................................*/
77 QState UI_initial(UI *me) {
\r
78 SerialCommand_init(&AO_UI.serialCommand);
79 return Q_TRAN(&UI_User);
81 /* $(AOs::UI::Statechart::User) ............................................*/
82 QState UI_User(UI *me) {
85 case SERIAL_RX_DATA_SIG: {
86 serialDispatch(&me->serialCommand, SERIAL_RX_DATA_SIG, Q_PAR(me));
90 case SERIAL_TX_EMPTY_SIG: {
91 serialDispatch(&me->serialCommand, SERIAL_TX_EMPTY_SIG, Q_PAR(me));
95 case COMMAND_FAIL_SIG: {
96 serialNACK(&me->serialCommand, 0);
100 case COMMAND_AZIMUTH_SIG: {
101 QActive_post((QActive *)&AO_azimuth, SET_BASE_SPEED_SIG, Q_PAR(me));
102 QActive_post((QActive *)&AO_azimuth, SET_ACCELERATION_SIG,
103 me->serialCommand.vargs[1].v.param);
104 QActive_post((QActive *)&AO_azimuth, SET_SLEW_SPEED_SIG,
105 me->serialCommand.vargs[2].v.param);
106 QActive_post((QActive *)&AO_azimuth, SET_TOTAL_STEPS_SIG,
107 me->serialCommand.vargs[3].v.param);
108 serialReleaseVargs(&me->serialCommand);
109 serialACK(&me->serialCommand, 1);
113 case COMMAND_AZIMUTH_BASE_SIG: {
114 QActive_post((QActive *)&AO_azimuth, SET_BASE_SPEED_SIG, Q_PAR(me));
115 serialACK(&me->serialCommand, 1);
119 case COMMAND_AZIMUTH_SLEW_SIG: {
120 QActive_post((QActive *)&AO_azimuth, SET_SLEW_SPEED_SIG, Q_PAR(me));
121 serialACK(&me->serialCommand, 1);
125 case COMMAND_AZIMUTH_ACCELERATION_SIG: {
126 QActive_post((QActive *)&AO_azimuth, SET_ACCELERATION_SIG, Q_PAR(me));
127 serialACK(&me->serialCommand, 1);
131 case COMMAND_AZIMUTH_STEPS_SIG: {
132 QActive_post((QActive *)&AO_azimuth, SET_TOTAL_STEPS_SIG, Q_PAR(me));
133 serialACK(&me->serialCommand, 1);
137 case COMMAND_ELEVATION_SIG: {
138 QActive_post((QActive *)&AO_elevation, SET_BASE_SPEED_SIG, Q_PAR(me));
139 QActive_post((QActive *)&AO_elevation, SET_ACCELERATION_SIG,
140 me->serialCommand.vargs[1].v.param);
141 QActive_post((QActive *)&AO_elevation, SET_SLEW_SPEED_SIG,
142 me->serialCommand.vargs[2].v.param);
143 QActive_post((QActive *)&AO_elevation, SET_TOTAL_STEPS_SIG,
144 me->serialCommand.vargs[3].v.param);
145 serialReleaseVargs(&me->serialCommand);
146 serialACK(&me->serialCommand, 1);
150 case COMMAND_ELEVATION_BASE_SIG: {
151 QActive_post((QActive *)&AO_elevation, SET_BASE_SPEED_SIG, Q_PAR(me));
152 serialACK(&me->serialCommand, 1);
156 case COMMAND_ELEVATION_SLEW_SIG: {
157 QActive_post((QActive *)&AO_elevation, SET_SLEW_SPEED_SIG, Q_PAR(me));
158 serialACK(&me->serialCommand, 1);
162 case COMMAND_ELEVATION_ACCELERATION_SIG: {
163 QActive_post((QActive *)&AO_elevation, SET_ACCELERATION_SIG, Q_PAR(me));
164 serialACK(&me->serialCommand, 1);
168 case COMMAND_ELEVATION_STEPS_SIG: {
169 QActive_post((QActive *)&AO_elevation, SET_TOTAL_STEPS_SIG, Q_PAR(me));
170 serialACK(&me->serialCommand, 1);
174 case SERIAL_RX_ERROR_SIG: {
175 serialDispatch(&me->serialCommand, SERIAL_RX_ERROR_SIG, Q_PAR(me));
179 case SERIAL_TX_COMPLETE_SIG: {
180 serialDispatch(&me->serialCommand, SERIAL_TX_COMPLETE_SIG, Q_PAR(me));
184 case COMMAND_START_AZIMUTH_SIG: {
185 QActive_post((QActive *)&AO_azimuth, START_LINEAR_SLEW_SIG, 0);
186 serialACK(&me->serialCommand, 1);
190 case COMMAND_START_ELEVATION_SIG: {
191 QActive_post((QActive *)&AO_elevation, START_LINEAR_SLEW_SIG, 0);
192 serialACK(&me->serialCommand, 1);
196 case COMMAND_START_AZ_EL_SIG: {
197 QActive_post((QActive *)&AO_azimuth, START_LINEAR_SLEW_SIG, 0);
198 QActive_post((QActive *)&AO_elevation, START_LINEAR_SLEW_SIG, 0);
199 serialACK(&me->serialCommand, 1);
203 case COMMAND_AZIMUTH_CLOCKWISE_SIG: {
204 QActive_post((QActive *)&AO_azimuth, SET_DIRECTION_UP_CW_SIG, 0);
205 serialACK(&me->serialCommand, 1);
209 case COMMAND_AZIMUTH_CCW_SIG: {
210 QActive_post((QActive *)&AO_azimuth, SET_DIRECTION_DOWN_CCW_SIG, 0);
211 serialACK(&me->serialCommand, 1);
215 case COMMAND_ELEVATION_UP_SIG: {
216 QActive_post((QActive *)&AO_elevation, SET_DIRECTION_UP_CW_SIG, 0);
217 serialACK(&me->serialCommand, 1);
221 case COMMAND_ELEVATION_DOWN_SIG: {
222 QActive_post((QActive *)&AO_elevation, SET_DIRECTION_DOWN_CCW_SIG, 0);
223 serialACK(&me->serialCommand, 1);
227 return Q_SUPER(&QHsm_top);